心血來潮,寫了一個算法驶睦,娛樂一下自己
```java
import java.util.Arrays;import java.util.Date;import java.util.List;public class NextDate {public static void main(String[] args) {Date date = new Date();date.setYear(116);date.setMonth(11);date.setDate(31);System.out.println(nextDate(date).toLocaleString());}public static Date nextDate(Date date) {//long l = date.getTime();//return new Date(l+24*60*60*1000);if (date==null) {return null;}if (isYearEnd(date)) {return new Date(date.getYear()+1,0,1);}else if (isSecondMonthEnd(date) || isOhterMonthEnd(date)) {return new Date(date.getYear(),date.getMonth()+1,1);}else {return new Date(date.getYear(),date.getMonth(),date.getDate()+1);}}private static boolean isYearEnd(Date date){if(date.getMonth()==11 && date.getDate()==31){return true;}else{return false;}}private static boolean isSecondMonthEnd(Date date){if(date.getMonth()!=1){return false;}else if (isLeapYear(date)) {return date.getDate()==29;}else{return false;}}//private static boolean isLeapYear(Date date){int year = date.getYear();if(year%4==0 && !(year%100==0) || year%400==0){return true;}else {return false;}}private static boolean isOhterMonthEnd(Date date){ListbigMonthList = Arrays.asList(new Integer[]{0,2,4,6,7,9,11});
if(bigMonthList.contains(date.getMonth())){
return date.getDate() == 31;
}
else{
return date.getDate() == 30;
}
}
}
```