@Test public void testGetAgeDetail() throws ParseException { Calendar startDate = DateUtils.getCalendar("2010-01-01"); Calendar endDate = DateUtils.getCalendar("2011-01-01"); int[] detail = DateUtils.getAgeDetail(startDate, endDate); Assert.assertEquals("1,0,1", detail[0] + "," + detail[1] + "," + detail[2]); startDate = DateUtils.getCalendar("2010-01-01"); endDate = DateUtils.getCalendar("2011-01-01"); detail = DateUtils.getAgeDetail(startDate, endDate); Assert.assertEquals("1,0,1", detail[0] + "," + detail[1] + "," + detail[2]); startDate = DateUtils.getCalendar("2010-02-01"); endDate = DateUtils.getCalendar("2011-01-01"); detail = DateUtils.getAgeDetail(startDate, endDate); Assert.assertEquals("0,11,1", detail[0] + "," + detail[1] + "," + detail[2]); startDate = DateUtils.getCalendar("2010-01-01"); endDate = DateUtils.getCalendar("2011-01-10"); detail = DateUtils.getAgeDetail(startDate, endDate); Assert.assertEquals("1,0,10", detail[0] + "," + detail[1] + "," + detail[2]); }
public static int[] getAgeDetail(Calendar startDate, Calendar endDate) { int startYeay = startDate.get(Calendar.YEAR); int startMonth = startDate.get(Calendar.MONTH); int endYeay = endDate.get(Calendar.YEAR); int endMonth = endDate.get(Calendar.MONTH); int[] detail = new int[3]; detail[0] = endYeay - startYeay - 1; detail[1] = 11 - startMonth + endMonth; int maxDay = getLastDayOfMonth(startDate).get(Calendar.DATE); detail[2] = maxDay - startDate.get(Calendar.DATE) + 1 + endDate.get(Calendar.DATE); if (detail[2] >= maxDay) { detail[1] += 1; detail[2] -= maxDay; } if (detail[1] >= 12) { detail[0] += 1; detail[1] -= 12; } return detail; }
DateUtils { public static int[] getAgeDetail(Calendar startDate, Calendar endDate) { int startYeay = startDate.get(Calendar.YEAR); int startMonth = startDate.get(Calendar.MONTH); int endYeay = endDate.get(Calendar.YEAR); int endMonth = endDate.get(Calendar.MONTH); int[] detail = new int[3]; detail[0] = endYeay - startYeay - 1; detail[1] = 11 - startMonth + endMonth; int maxDay = getLastDayOfMonth(startDate).get(Calendar.DATE); detail[2] = maxDay - startDate.get(Calendar.DATE) + 1 + endDate.get(Calendar.DATE); if (detail[2] >= maxDay) { detail[1] += 1; detail[2] -= maxDay; } if (detail[1] >= 12) { detail[0] += 1; detail[1] -= 12; } return detail; } }
DateUtils { public static int[] getAgeDetail(Calendar startDate, Calendar endDate) { int startYeay = startDate.get(Calendar.YEAR); int startMonth = startDate.get(Calendar.MONTH); int endYeay = endDate.get(Calendar.YEAR); int endMonth = endDate.get(Calendar.MONTH); int[] detail = new int[3]; detail[0] = endYeay - startYeay - 1; detail[1] = 11 - startMonth + endMonth; int maxDay = getLastDayOfMonth(startDate).get(Calendar.DATE); detail[2] = maxDay - startDate.get(Calendar.DATE) + 1 + endDate.get(Calendar.DATE); if (detail[2] >= maxDay) { detail[1] += 1; detail[2] -= maxDay; } if (detail[1] >= 12) { detail[0] += 1; detail[1] -= 12; } return detail; }  }
DateUtils { public static int[] getAgeDetail(Calendar startDate, Calendar endDate) { int startYeay = startDate.get(Calendar.YEAR); int startMonth = startDate.get(Calendar.MONTH); int endYeay = endDate.get(Calendar.YEAR); int endMonth = endDate.get(Calendar.MONTH); int[] detail = new int[3]; detail[0] = endYeay - startYeay - 1; detail[1] = 11 - startMonth + endMonth; int maxDay = getLastDayOfMonth(startDate).get(Calendar.DATE); detail[2] = maxDay - startDate.get(Calendar.DATE) + 1 + endDate.get(Calendar.DATE); if (detail[2] >= maxDay) { detail[1] += 1; detail[2] -= maxDay; } if (detail[1] >= 12) { detail[0] += 1; detail[1] -= 12; } return detail; }  static String formatDate(Date date); static String formatCalendar2Day(Calendar calendar); static String formatDateTime(Date date); static String formatCalendar2Second(Calendar calendar); static String formatDateTime2Minute(Date date); static String formatCalendar2Minute(Calendar calendar); static String formatDateTime(Date date, String format); static String formatCalendar(Calendar calendar, String format); static int getHour(Date date); static int getMinute(Date date); static Calendar getCalendar(String dateTime); static Date getDate(String dateTime); static Date getDateEx(String dateTime); static Calendar getCalendarEx(String dateTime); static Calendar getFirstDayOfMonth(Calendar calendar); static Calendar getLastDayOfMonth(Calendar calendar); static void setToFirstDayOfMonth(Calendar calendar); static void setToLastDayOfMonth(Calendar calendar); static void setToZeroTime(Calendar calendar); @SuppressWarnings("deprecation") static void setToZeroTime(Date date); static void setToMaxTime(Calendar calendar); @SuppressWarnings("deprecation") static void setToMaxTime(Date date); static Date getZeroTimeDate(Date date); static Date getMaxTimeDate(Date date); static String getWasteTime(Date fromDate); static String getWasteTimeCN(Date fromDate); static String getWasteTime(Date startDate, Date endDate); static String getWasteTimeCN(Date startDate, Date endDate); static String getWasteTime(long wt); static String getWasteTimeCN(long wt); static float getAge(Date startDate, Date endDate); static float getAge(Calendar startDate, Calendar endDate); static float getAge(Calendar birthDate); static int[] getAgeDetail(Calendar startDate, Calendar endDate); static String getWeekCN(Calendar date); static Calendar getFirstDayOfNextMonth(Calendar calendar); static Calendar getLastDayOfNextMonth(Calendar calendar); static Calendar getDate4Range(Calendar calendar, String rangeConfig); static boolean isMonthEnd(Calendar calendar); }
DateUtils { public static int[] getAgeDetail(Calendar startDate, Calendar endDate) { int startYeay = startDate.get(Calendar.YEAR); int startMonth = startDate.get(Calendar.MONTH); int endYeay = endDate.get(Calendar.YEAR); int endMonth = endDate.get(Calendar.MONTH); int[] detail = new int[3]; detail[0] = endYeay - startYeay - 1; detail[1] = 11 - startMonth + endMonth; int maxDay = getLastDayOfMonth(startDate).get(Calendar.DATE); detail[2] = maxDay - startDate.get(Calendar.DATE) + 1 + endDate.get(Calendar.DATE); if (detail[2] >= maxDay) { detail[1] += 1; detail[2] -= maxDay; } if (detail[1] >= 12) { detail[0] += 1; detail[1] -= 12; } return detail; }  static String formatDate(Date date); static String formatCalendar2Day(Calendar calendar); static String formatDateTime(Date date); static String formatCalendar2Second(Calendar calendar); static String formatDateTime2Minute(Date date); static String formatCalendar2Minute(Calendar calendar); static String formatDateTime(Date date, String format); static String formatCalendar(Calendar calendar, String format); static int getHour(Date date); static int getMinute(Date date); static Calendar getCalendar(String dateTime); static Date getDate(String dateTime); static Date getDateEx(String dateTime); static Calendar getCalendarEx(String dateTime); static Calendar getFirstDayOfMonth(Calendar calendar); static Calendar getLastDayOfMonth(Calendar calendar); static void setToFirstDayOfMonth(Calendar calendar); static void setToLastDayOfMonth(Calendar calendar); static void setToZeroTime(Calendar calendar); @SuppressWarnings("deprecation") static void setToZeroTime(Date date); static void setToMaxTime(Calendar calendar); @SuppressWarnings("deprecation") static void setToMaxTime(Date date); static Date getZeroTimeDate(Date date); static Date getMaxTimeDate(Date date); static String getWasteTime(Date fromDate); static String getWasteTimeCN(Date fromDate); static String getWasteTime(Date startDate, Date endDate); static String getWasteTimeCN(Date startDate, Date endDate); static String getWasteTime(long wt); static String getWasteTimeCN(long wt); static float getAge(Date startDate, Date endDate); static float getAge(Calendar startDate, Calendar endDate); static float getAge(Calendar birthDate); static int[] getAgeDetail(Calendar startDate, Calendar endDate); static String getWeekCN(Calendar date); static Calendar getFirstDayOfNextMonth(Calendar calendar); static Calendar getLastDayOfNextMonth(Calendar calendar); static Calendar getDate4Range(Calendar calendar, String rangeConfig); static boolean isMonthEnd(Calendar calendar); static Map<String, String> dateFormats; }