JAVA计算给Date日期增加分钟后的Date

//date是要增加的日期,min是要增加的分钟数
private Date addDate(Date date,int min) throws ParseException {Calendar calendar=new GregorianCalendar();calendar.setTime(date);int year1=calendar.get(Calendar.YEAR);int month2=calendar.get(Calendar.MONTH)+1;int day1=calendar.get(Calendar.DATE);int hour1=calendar.get(Calendar.HOUR_OF_DAY);int min1=calendar.get(Calendar.MINUTE);int sec1=calendar.get(Calendar.SECOND);int hour2=min/60;int min2=min%60;int min3=min1+min2;if((min1+min2)>=60){hour2+=(min1+min2)/60;min3=(min1+min2)%60;}int hour3=hour2+hour1;if((hour2+hour1)>24){if(month2==1||month2==3||month2==5||month2==7||month2==8||month2==10||month2==12){if(day1==31){month2++;day1=1;}else day1++;}else if(month2==4||month2==6||month2==9||month2==11){if(day1==30){month2++;day1=1;}else day1++;}else if(month2==2){if(year1%4==0){if(day1==29){month2++;day1=1;}else day1++;}else {if(day1==28){month2++;day1=1;}else day1++;}}hour3=(hour2+hour1)%24;}if(month2==13){month2=1;year1++;}SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");String x = year1 + "-" + month2 + "-" + day1 + " " + hour3 + ":" + min3 + ":" + sec1;System.out.println(x);return sdf.parse(x);}

JAVA计算给Date日期增加分钟后的Date

//date是要增加的日期,min是要增加的分钟数
private Date addDate(Date date,int min) throws ParseException {Calendar calendar=new GregorianCalendar();calendar.setTime(date);int year1=calendar.get(Calendar.YEAR);int month2=calendar.get(Calendar.MONTH)+1;int day1=calendar.get(Calendar.DATE);int hour1=calendar.get(Calendar.HOUR_OF_DAY);int min1=calendar.get(Calendar.MINUTE);int sec1=calendar.get(Calendar.SECOND);int hour2=min/60;int min2=min%60;int min3=min1+min2;if((min1+min2)>=60){hour2+=(min1+min2)/60;min3=(min1+min2)%60;}int hour3=hour2+hour1;if((hour2+hour1)>24){if(month2==1||month2==3||month2==5||month2==7||month2==8||month2==10||month2==12){if(day1==31){month2++;day1=1;}else day1++;}else if(month2==4||month2==6||month2==9||month2==11){if(day1==30){month2++;day1=1;}else day1++;}else if(month2==2){if(year1%4==0){if(day1==29){month2++;day1=1;}else day1++;}else {if(day1==28){month2++;day1=1;}else day1++;}}hour3=(hour2+hour1)%24;}if(month2==13){month2=1;year1++;}SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");String x = year1 + "-" + month2 + "-" + day1 + " " + hour3 + ":" + min3 + ":" + sec1;System.out.println(x);return sdf.parse(x);}