如果我知道月底的星期几(星期一,星期二,星期三……)和月(一月,二月……),怎么知道呢? ),例如,据我所知,如果您从星期一开始,则一月的星期名称以您结尾。
最佳答案
使用java.time
类有很多方法可以查找月份中最后一天的星期几,例如:
LocalDate firstDay = LocalDate.of(2018, 1, 1);
DayOfWeek firstDOW = firstDay.getDayOfWeek();
LocalDate lastDay = YearMonth.of(firstDay.getYear(), firstDay.getMonth()).atEndOfMonth();
DayOfWeek lastDOW = lastDay.getDayOfWeek();
LocalDate lastDay2 = LocalDate.of(firstDay.getYear(), firstDay.getMonth(), firstDay.lengthOfMonth());
LocalDate lastDay3 = firstDay.plusDays(firstDay.lengthOfMonth() - firstDay.getDayOfMonth());