DateUtil { public static String date2String(final Date date) { return date2String(date, DateConstants.DATETIME_FORMAT_19); }  static Date string2Date(final String ds); static Date string2Date(final String date, final String format); static String date2String(final Date date); static String date2String(final Date date, final String format); static String getCurrentTimestamp(); static long getCurrentTime(); static Date getCurrentDate(); static int daysBetween(final Date startDate); static Date getYrMonthLastDay(final Date d); static Date getYrMonthFirstDay(final Date d); static int daysBetween(final Date startDate, final Date endDate);  }
@Test public void date2String() { Date date = new Date(NUM_C); String d8 = DateUtil.date2String(date, DateConstants.DATE_FORMAT_8); Assert.equals(d8, "20180912", ErrorCodeDef.SYSTEM_ERROR_10001); String d11 = DateUtil.date2String(date, DateConstants.DATE_FORMAT_11); Assert.equals(d11, "2018年09月12日", ErrorCodeDef.SYSTEM_ERROR_10001); String d10 = DateUtil.date2String(date, DateConstants.DATE_FORMAT_10); Assert.equals(d10, "2018-09-12", ErrorCodeDef.SYSTEM_ERROR_10001); String d102 = DateUtil.date2String(date, DateConstants.DATE_FORMAT_10_2); Assert.equals(d102, "2018/09/12", ErrorCodeDef.SYSTEM_ERROR_10001); String d14 = DateUtil.date2String(date, DateConstants.DATETIME_FORMAT_14); Assert.equals(d14, "20180912105355", ErrorCodeDef.SYSTEM_ERROR_10001); String d17 = DateUtil.date2String(date, DateConstants.DATETIME_FORMAT_17); Assert.equals(d17, "20180912105355123", ErrorCodeDef.SYSTEM_ERROR_10001); String d19 = DateUtil.date2String(date); Assert.equals(d19, "2018-09-12 10:53:55", ErrorCodeDef.SYSTEM_ERROR_10001); String d192 = DateUtil.date2String(date, DateConstants.DATETIME_FORMAT_19_2); Assert.equals(d192, "2018/09/12 10:53:55", ErrorCodeDef.SYSTEM_ERROR_10001); String d21 = DateUtil.date2String(date, DateConstants.DATETIME_FORMAT_21); Assert.equals(d21, "2018年09月12日 10时53分55秒", ErrorCodeDef.SYSTEM_ERROR_10001); String d23 = DateUtil.date2String(date, DateConstants.DATETIME_FORMAT_23); Assert.equals(d23, "2018-09-12 10:53:55.123", ErrorCodeDef.SYSTEM_ERROR_10001); String d232 = DateUtil.date2String(date, DateConstants.DATETIME_FORMAT_23_2); Assert.equals(d232, "2018/09/12 10:53:55.123", ErrorCodeDef.SYSTEM_ERROR_10001); String str = DateUtil.date2String(date, "yy年M月dd号hh点mm分ss秒"); Assert.equals(str, "18年9月12号10点53分55秒", ErrorCodeDef.SYSTEM_ERROR_10001); }