指定时间增加年月日

public static String calendarMethod(String time, int year, int month, int day, int hour, int min, int sec) {
//时分秒默认是 00:00:00
SimpleDateFormat sdate = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
date = sdate.parse(time);
} catch (Exception e) {
log.error("异常[{}]", e.toString());
return null;
}
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.YEAR, year);
c.add(Calendar.MONTH, month);
c.add(Calendar.DAY_OF_MONTH, day);
c.add(Calendar.HOUR_OF_DAY, hour);
c.add(Calendar.MINUTE, min);
c.add(Calendar.SECOND, sec);
SimpleDateFormat sdate1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdate1.format(c.getTime());
}

猜你喜欢

转载自www.cnblogs.com/lcxdevelop/p/11230773.html