@Test public void testAddDate() { Calendar now = Calendar.getInstance(); Date date = now.getTime(); Date pastDate = DateUtils.addDate(date, -1, -2, -3); Calendar past = Calendar.getInstance(); past.setTime(pastDate); Calendar copy = (Calendar) now.clone(); copy.add(Calendar.YEAR, -1); copy.add(Calendar.MONTH, -2); copy.add(Calendar.DAY_OF_MONTH, -3); assertEquals(past.get(Calendar.YEAR), copy.get(Calendar.YEAR)); assertEquals(past.get(Calendar.MONTH), copy.get(Calendar.MONTH)); assertEquals(past.get(Calendar.DAY_OF_MONTH), copy.get(Calendar.DAY_OF_MONTH)); }
public static Date addDate(Date date, int years, int months, int days) { Calendar calendar = Calendar.getInstance(); if (date!=null) calendar.setTime(date); if (years!=0) calendar.add(Calendar.YEAR, years); if (months!=0) calendar.add(Calendar.MONTH, months); if (days!=0) calendar.add(Calendar.DAY_OF_MONTH, days); return calendar.getTime(); }
DateUtils { public static Date addDate(Date date, int years, int months, int days) { Calendar calendar = Calendar.getInstance(); if (date!=null) calendar.setTime(date); if (years!=0) calendar.add(Calendar.YEAR, years); if (months!=0) calendar.add(Calendar.MONTH, months); if (days!=0) calendar.add(Calendar.DAY_OF_MONTH, days); return calendar.getTime(); } }
DateUtils { public static Date addDate(Date date, int years, int months, int days) { Calendar calendar = Calendar.getInstance(); if (date!=null) calendar.setTime(date); if (years!=0) calendar.add(Calendar.YEAR, years); if (months!=0) calendar.add(Calendar.MONTH, months); if (days!=0) calendar.add(Calendar.DAY_OF_MONTH, days); return calendar.getTime(); } private  DateUtils(); }
DateUtils { public static Date addDate(Date date, int years, int months, int days) { Calendar calendar = Calendar.getInstance(); if (date!=null) calendar.setTime(date); if (years!=0) calendar.add(Calendar.YEAR, years); if (months!=0) calendar.add(Calendar.MONTH, months); if (days!=0) calendar.add(Calendar.DAY_OF_MONTH, days); return calendar.getTime(); } private  DateUtils(); static Date getDateNow(); static Date getTimeNow(); static Date addDate(Date date, int years, int months, int days); static Date setDate(Date date, int year, int month, int day); static Date getDate(int year, int month, int day); static Date setTime(Date date, int hours, int minutes, int seconds, int millis); static Date getDateOnly(Date date); static Date parseDate(String sDate, Locale locale); static String formatDate(Date d, Locale locale); static String formatTime(Date d, Locale locale, boolean withSeconds); static String formatDayOfWeek(Date d, Locale locale, boolean longFormat); static String formatMonth(Date d, Locale locale, boolean longFormat); static int getWeekOfYear(Date d, Locale locale); static String formatMonth(int month, Locale locale, boolean longFormat); static String formatYear(Date d, Locale locale); }
DateUtils { public static Date addDate(Date date, int years, int months, int days) { Calendar calendar = Calendar.getInstance(); if (date!=null) calendar.setTime(date); if (years!=0) calendar.add(Calendar.YEAR, years); if (months!=0) calendar.add(Calendar.MONTH, months); if (days!=0) calendar.add(Calendar.DAY_OF_MONTH, days); return calendar.getTime(); } private  DateUtils(); static Date getDateNow(); static Date getTimeNow(); static Date addDate(Date date, int years, int months, int days); static Date setDate(Date date, int year, int month, int day); static Date getDate(int year, int month, int day); static Date setTime(Date date, int hours, int minutes, int seconds, int millis); static Date getDateOnly(Date date); static Date parseDate(String sDate, Locale locale); static String formatDate(Date d, Locale locale); static String formatTime(Date d, Locale locale, boolean withSeconds); static String formatDayOfWeek(Date d, Locale locale, boolean longFormat); static String formatMonth(Date d, Locale locale, boolean longFormat); static int getWeekOfYear(Date d, Locale locale); static String formatMonth(int month, Locale locale, boolean longFormat); static String formatYear(Date d, Locale locale);  }