java常用的时间工具
1、在原日期的基础上增加天数
/*** 在原日期的基础上增加天数*/public static Date add(Date date, int num) {Calendar calendar = Calendar.getInstance();calendar.setTime(date);calendar.add(Calendar.DAY_OF_MONTH, num);return calendar.getTime();}
2、在原日期的基础上增加小时、分钟
/*** 在原日期的基础上增加小时、分钟*/public static Date addHourMinute(Date date,Date time){Calendar oldTime = Calendar.getInstance();Calendar newTime = Calendar.getInstance();oldTime.setTime(date);newTime.setTime(time);oldTime.set(Calendar.HOUR_OF_DAY, newTime.get(Calendar.HOUR_OF_DAY));oldTime.set(Calendar.MINUTE, newTime.get(Calendar.MINUTE));Date newDate = oldTime.getTime();return newDate;}