DateUtils { public static Date millisStrToDate(String millisDateStr) throws ParseException { return strToDate(millisDateStr, DATE_FORMAT_MILLS_TIME); }  static int getDelayToNextMinute(long rightnow); static long getPreMinuteMills(long rightnow); static String dateToStr(Date date); static String dateToStr(Date date, String format); static Date strToDate(String dateStr); static Long strToLong(String dateStr); static Date strToDate(String dateStr, String format); static String dateToMillisStr(Date date); static Date millisStrToDate(String millisDateStr); static final int MILLISECONDS_PER_SECONDE; static final int MILLISECONDS_PER_MINUTE; static final int MILLISECONDS_PER_HOUR; static final long MILLISECONDS_PER_DAY; static final String DATE_FORMAT_TIME; static final String DATE_FORMAT_MILLS_TIME; }
@Test public void millisStrToDate() throws Exception { long d0 = 0l; long d1 = 1501127802975l; long d2 = 1501127835658l; TimeZone timeZone = TimeZone.getDefault(); Date date0 = new Date(d0 - timeZone.getOffset(d0)); Date date1 = new Date(d1 - timeZone.getOffset(d1)); Date date2 = new Date(d2 - timeZone.getOffset(d2)); String s0 = "1970-01-01 00:00:00.000"; String s1 = "2017-07-27 03:56:42.975"; String s2 = "2017-07-27 03:57:15.658"; Assert.assertEquals(DateUtils.millisStrToDate(s0).getTime(), date0.getTime()); Assert.assertEquals(DateUtils.millisStrToDate(s1).getTime(), date1.getTime()); Assert.assertEquals(DateUtils.millisStrToDate(s2).getTime(), date2.getTime()); }