package com.uas.report.util; import java.util.Calendar; import java.util.Date; /** * 对时间的操作 * * @author sunyj * @since 2016年9月27日 下午8:10:50 */ public class TimeUtils { /** * Adds or subtracts the specified amount of time to the given calendar * field, based on the calendar's rules. For example, to subtract 5 days * from the specified time of the calendar, you can achieve it by calling: * add(time, Calendar.DAY_OF_MONTH, -5). * * @param time * @param field * @param amount * @return */ public static Date add(Date time, int field, int amount) { Calendar calendar = Calendar.getInstance(); calendar.setTime(time); calendar.add(field, amount); return calendar.getTime(); } }