@Test public void testRound1(){ long tsInMS = 1397016731576L; long tsInMin = DateTimeUtil.roundDown(Calendar.MINUTE, tsInMS); Assert.assertEquals(1397016720000L, tsInMin); GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(tsInMS); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Assert.assertEquals(tsInMin, cal.getTimeInMillis()); }
public static long roundDown(int field, long timeInMillis){ switch(field){ case Calendar.DAY_OF_MONTH: case Calendar.DAY_OF_WEEK: case Calendar.DAY_OF_YEAR: return (timeInMillis - timeInMillis % (24*60*60*1000)); case Calendar.HOUR: return (timeInMillis - timeInMillis % (60*60*1000)); case Calendar.MINUTE: return (timeInMillis - timeInMillis % (60*1000)); case Calendar.SECOND: return (timeInMillis - timeInMillis % (1000)); default: return 0L; } }
DateTimeUtil { public static long roundDown(int field, long timeInMillis){ switch(field){ case Calendar.DAY_OF_MONTH: case Calendar.DAY_OF_WEEK: case Calendar.DAY_OF_YEAR: return (timeInMillis - timeInMillis % (24*60*60*1000)); case Calendar.HOUR: return (timeInMillis - timeInMillis % (60*60*1000)); case Calendar.MINUTE: return (timeInMillis - timeInMillis % (60*1000)); case Calendar.SECOND: return (timeInMillis - timeInMillis % (1000)); default: return 0L; } } }
DateTimeUtil { public static long roundDown(int field, long timeInMillis){ switch(field){ case Calendar.DAY_OF_MONTH: case Calendar.DAY_OF_WEEK: case Calendar.DAY_OF_YEAR: return (timeInMillis - timeInMillis % (24*60*60*1000)); case Calendar.HOUR: return (timeInMillis - timeInMillis % (60*60*1000)); case Calendar.MINUTE: return (timeInMillis - timeInMillis % (60*1000)); case Calendar.SECOND: return (timeInMillis - timeInMillis % (1000)); default: return 0L; } }  }
DateTimeUtil { public static long roundDown(int field, long timeInMillis){ switch(field){ case Calendar.DAY_OF_MONTH: case Calendar.DAY_OF_WEEK: case Calendar.DAY_OF_YEAR: return (timeInMillis - timeInMillis % (24*60*60*1000)); case Calendar.HOUR: return (timeInMillis - timeInMillis % (60*60*1000)); case Calendar.MINUTE: return (timeInMillis - timeInMillis % (60*1000)); case Calendar.SECOND: return (timeInMillis - timeInMillis % (1000)); default: return 0L; } }  static Date humanDateToDate(String date); static String secondsToHumanDate(long seconds); static String millisecondsToHumanDateWithMilliseconds(long milliseconds); static String millisecondsToHumanDateWithSeconds(long milliseconds); static long humanDateToSeconds(String date); static long humanDateToMilliseconds(String date); static long humanDateToMillisecondsWithoutException(String date); static long humanDateToSecondsWithoutException(String date); static long roundDown(int field, long timeInMillis); static String format(long milliseconds, String format); }
DateTimeUtil { public static long roundDown(int field, long timeInMillis){ switch(field){ case Calendar.DAY_OF_MONTH: case Calendar.DAY_OF_WEEK: case Calendar.DAY_OF_YEAR: return (timeInMillis - timeInMillis % (24*60*60*1000)); case Calendar.HOUR: return (timeInMillis - timeInMillis % (60*60*1000)); case Calendar.MINUTE: return (timeInMillis - timeInMillis % (60*1000)); case Calendar.SECOND: return (timeInMillis - timeInMillis % (1000)); default: return 0L; } }  static Date humanDateToDate(String date); static String secondsToHumanDate(long seconds); static String millisecondsToHumanDateWithMilliseconds(long milliseconds); static String millisecondsToHumanDateWithSeconds(long milliseconds); static long humanDateToSeconds(String date); static long humanDateToMilliseconds(String date); static long humanDateToMillisecondsWithoutException(String date); static long humanDateToSecondsWithoutException(String date); static long roundDown(int field, long timeInMillis); static String format(long milliseconds, String format); static final long ONESECOND; static final long ONEMINUTE; static final long ONEHOUR; static final long ONEDAY; }