//获取两个日期之间的相差天数
public static int differentDaysByMillisecond(Date date1, Date date2){
int days = (int) ((date2.getTime() - date1.getTime()) / (1000*3600*24));
return days;
}
//
public static Date getOperateDate(Date time) {
Calendar calendar = Calendar.getInstance().getInstance();
calendar.setTime(time);
calendar.add(Calendar.MONTH, 1);
calendar.set(Calendar.DAY_OF_MONTH, 5);
return calendar.getTime();
}
public static void main(String[] args) throws ParseException {
Date repaymentTime = new SimpleDateFormat("yyyy-MM-dd").parse("2017-1-5");
Date nowTime = new SimpleDateFormat("yyyy-MM-dd").parse("2017-2-27");
System.out.println("相差天数:" + differentDaysByMillisecond(repaymentTime, nowTime));
System.out.println("处理后的日期:" + getOperateDate(new Date()));
}
时间: 2024-10-11 12:32:11