@Test public void testGetDateEx() throws ParseException { Assert.assertEquals("2013-01-21 01:02:03", formater.format(DateUtils.getDateEx("2013-01-21 01:02:03"))); Assert.assertEquals("2013-01-21 01:02:03", formater.format(DateUtils.getDateEx("2013-1-21 1:2:3"))); Assert.assertEquals("2013-01-21 01:02:00", formater.format(DateUtils.getDateEx("2013-01-21 01:02"))); Assert.assertEquals("2013-01-02 01:02:00", formater.format(DateUtils.getDateEx("2013-1-2 1:2"))); Assert.assertEquals("2013-01-21 00:00:00", formater.format(DateUtils.getDateEx("2013-01-21"))); Assert.assertEquals("2013-01-02 00:00:00", formater.format(DateUtils.getDateEx("2013-1-2"))); Assert.assertEquals("2013-01-21 01:02:03", formater.format(DateUtils.getDateEx("2013/01/21 01:02:03"))); Assert.assertEquals("2013-01-21 01:02:03", formater.format(DateUtils.getDateEx("2013/1/21 1:2:3"))); Assert.assertEquals("2013-01-21 01:02:00", formater.format(DateUtils.getDateEx("2013/01/21 01:02"))); Assert.assertEquals("2013-01-02 01:02:00", formater.format(DateUtils.getDateEx("2013/1/2 1:2"))); Assert.assertEquals("2013-01-21 00:00:00", formater.format(DateUtils.getDateEx("2013/01/21"))); Assert.assertEquals("2013-01-02 00:00:00", formater.format(DateUtils.getDateEx("2013/1/2"))); Assert.assertEquals("2013-01-21 01:02:03", formater.format(DateUtils.getDateEx("2013.01.21 01:02:03"))); Assert.assertEquals("2013-01-21 01:02:03", formater.format(DateUtils.getDateEx("2013.1.21 1:2:3"))); Assert.assertEquals("2013-01-21 01:02:00", formater.format(DateUtils.getDateEx("2013.01.21 01:02"))); Assert.assertEquals("2013-01-02 01:02:00", formater.format(DateUtils.getDateEx("2013.1.2 1:2"))); Assert.assertEquals("2013-01-21 00:00:00", formater.format(DateUtils.getDateEx("2013.01.21"))); Assert.assertEquals("2013-01-02 00:00:00", formater.format(DateUtils.getDateEx("2013.1.2"))); Assert.assertEquals("2013-01-21 00:00:00", formater.format(DateUtils.getDateEx("2013年01月21日"))); Assert.assertEquals("2013-01-02 00:00:00", formater.format(DateUtils.getDateEx("2013年1月2日"))); }
public static Date getDateEx(String dateTime) { if (dateTime == null) return null; dateTime = dateTime.trim(); if (dateTime.isEmpty()) return null; for (Entry<String, String> e : dateFormats.entrySet()) { if (Pattern.matches(e.getValue(), dateTime)) { FastDateFormat df4ex = FastDateFormat.getInstance(e.getKey()); try { return df4ex.parse(dateTime); } catch (ParseException e1) { logger.warn("Unparseable date: dateTime=" + dateTime + ",error=" + e1.getMessage()); throw new CoreException("Unparseable date: " + dateTime, e1); } } } logger.warn("can't parse this string to date: " + dateTime); throw new CoreException("can't parse this string to Date: " + dateTime); }
DateUtils { public static Date getDateEx(String dateTime) { if (dateTime == null) return null; dateTime = dateTime.trim(); if (dateTime.isEmpty()) return null; for (Entry<String, String> e : dateFormats.entrySet()) { if (Pattern.matches(e.getValue(), dateTime)) { FastDateFormat df4ex = FastDateFormat.getInstance(e.getKey()); try { return df4ex.parse(dateTime); } catch (ParseException e1) { logger.warn("Unparseable date: dateTime=" + dateTime + ",error=" + e1.getMessage()); throw new CoreException("Unparseable date: " + dateTime, e1); } } } logger.warn("can't parse this string to date: " + dateTime); throw new CoreException("can't parse this string to Date: " + dateTime); } }
DateUtils { public static Date getDateEx(String dateTime) { if (dateTime == null) return null; dateTime = dateTime.trim(); if (dateTime.isEmpty()) return null; for (Entry<String, String> e : dateFormats.entrySet()) { if (Pattern.matches(e.getValue(), dateTime)) { FastDateFormat df4ex = FastDateFormat.getInstance(e.getKey()); try { return df4ex.parse(dateTime); } catch (ParseException e1) { logger.warn("Unparseable date: dateTime=" + dateTime + ",error=" + e1.getMessage()); throw new CoreException("Unparseable date: " + dateTime, e1); } } } logger.warn("can't parse this string to date: " + dateTime); throw new CoreException("can't parse this string to Date: " + dateTime); }  }
DateUtils { public static Date getDateEx(String dateTime) { if (dateTime == null) return null; dateTime = dateTime.trim(); if (dateTime.isEmpty()) return null; for (Entry<String, String> e : dateFormats.entrySet()) { if (Pattern.matches(e.getValue(), dateTime)) { FastDateFormat df4ex = FastDateFormat.getInstance(e.getKey()); try { return df4ex.parse(dateTime); } catch (ParseException e1) { logger.warn("Unparseable date: dateTime=" + dateTime + ",error=" + e1.getMessage()); throw new CoreException("Unparseable date: " + dateTime, e1); } } } logger.warn("can't parse this string to date: " + dateTime); throw new CoreException("can't parse this string to Date: " + dateTime); }  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 Date getDateEx(String dateTime) { if (dateTime == null) return null; dateTime = dateTime.trim(); if (dateTime.isEmpty()) return null; for (Entry<String, String> e : dateFormats.entrySet()) { if (Pattern.matches(e.getValue(), dateTime)) { FastDateFormat df4ex = FastDateFormat.getInstance(e.getKey()); try { return df4ex.parse(dateTime); } catch (ParseException e1) { logger.warn("Unparseable date: dateTime=" + dateTime + ",error=" + e1.getMessage()); throw new CoreException("Unparseable date: " + dateTime, e1); } } } logger.warn("can't parse this string to date: " + dateTime); throw new CoreException("can't parse this string to Date: " + dateTime); }  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; }