JAVA获取月份的所有日期-CSDN博客
package com.test;import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;public class Test007 {public static void main(String[] args) throws ParseException {System.out.println(getDayOfMonth());String s="2024-11-02";System.out.println(s.substring(s.indexOf("-")+1));}private static List<String> getDayOfMonth() {List<String> list = new ArrayList<>();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");Calendar calendar = Calendar.getInstance();calendar.add(Calendar.MONTH,0 );calendar.set(Calendar.DAY_OF_MONTH, 1);int max = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);for (int i = 0; i < max; i++) {calendar.set(Calendar.DAY_OF_MONTH, i + 1);String day = sdf.format(calendar.getTime());list.add(day);}return list;}
}