Here you can find the source of getAfter(Date comparedDate, int cursor, String unit)
public static Date getAfter(Date comparedDate, int cursor, String unit)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; public class Main { public static String YEAR = "year"; public static String MONTH = "month"; public static String DAY = "day"; public static String HOUR = "hour"; public static String MINUTE = "minute"; public static String SECOND = "second"; public static Date getAfter(Date comparedDate, int cursor, String unit) { Calendar calendar = Calendar.getInstance(); calendar.setTime(comparedDate);//w w w.ja v a 2s . co m int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int date = calendar.get(Calendar.DATE); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); if (unit.equalsIgnoreCase(SECOND)) { second += cursor; } else if (unit.equalsIgnoreCase(MINUTE)) { minute += cursor; } else if (unit.equalsIgnoreCase(HOUR)) { hour += cursor; } else if (unit.equalsIgnoreCase(DAY)) { date += cursor; } else if (unit.equalsIgnoreCase(MONTH)) { month += cursor; } else if (unit.equalsIgnoreCase(YEAR)) { year += cursor; } calendar.set(year, month, date, hour, minute, second); return calendar.getTime(); } }