public String dateProcessing(String time) {
int year = Integer.parseInt(time.substring(0, 4));
int month = Integer.parseInt(time.substring(5, 7));
int day = Integer.parseInt(time.substring(8));
int days = 0;
//首先确定当月是多少天
if (month != 2) {
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
case 4:
case 6:
case 9:
case 11:
days = 30;
}
} else {
// 闰年
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
days = 29;
else
days = 28;
}
System.out.println("当月有" + days + "天!");
//如果当前时间 + 1 小于当月最大月份 说明没有到月的最后一天
if (day + 1 <= days) {
int dayNum = Integer.parseInt(time.substring(time.length() - 2)) + 1;
String substring = time.substring(0, time.length() - 2);
return dayNum >= 10 ? substring + dayNum : substring + "0" + dayNum;
} else {
//判断是否为12月 如果是说明时间是 yyyy-12-31 需要增加年份
if (month == 12) {
int yearNew = year + 1;
int monthNew = 1;
int dayNew = 1;
return yearNew + "-" + "0" + monthNew + "-" + "0" + dayNew;
} else {
//没有的话 月份切换到下一个月
int monthNew = month + 1;
int dayNew = 1;
return year + "-" + "0" + monthNew + "-" + "0" + dayNew;
}
}
}