List of utility methods to do TimeUnit Usage
long | getTomorrowTimestamp() get Tomorrow Timestamp Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return TimeUnit.SECONDS.convert(cal.getTimeInMillis(), TimeUnit.MILLISECONDS);
|
TimeUnit | getUnit(long nanos) get Unit for (TimeUnit unit : TimeUnit.values()) { long current = unit.convert(nanos, TimeUnit.NANOSECONDS); if (current < 1000) { return unit; return TimeUnit.NANOSECONDS; |
String | getValidityAsString(Date endDate) get Validity As String final long timeDiff = getTimeLeft(endDate); return getFormattedTime(timeDiff); |
T | getWithTimeout(final Future Calls Future#get(long,TimeUnit) with TestUtils#TIMEOUT in seconds. return future.get(TIMEOUT, TimeUnit.SECONDS);
|
String | humanizeTime(long hours, long minutes, long seconds) humanize Time StringBuilder builder = new StringBuilder(); if (hours == 0 && minutes != 0) { addMinutes(builder, minutes); } else if (hours != 0) { addHours(builder, hours); addMinutes(builder, minutes); addSeconds(builder, seconds); ... |
String | humanizeToTime(long millis) humanize To Time if (millis < 1000) return millis + " ms"; if (millis < 1000 * 60) return TimeUnit.MILLISECONDS.toSeconds(millis) + " sec (" + millis + " ms)"; else return String.format("%02d min, %02d sec (%d ms)", TimeUnit.MILLISECONDS.toMinutes(millis), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)), ... |
String | humanReadableDuration(Date from, Date to) Prints time duration in pretty form. StringBuilder sb = new StringBuilder(); if (from == null) { return ""; if (to == null) { return ""; long millis = to.getTime() - from.getTime(); ... |
String | humanReadableMillis(long millis) Get a human readable time milliseconds return String.format("%d hours %d minutes, %d seconds", TimeUnit.MILLISECONDS.toHours(millis), TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.MINUTES.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)), TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))); |
boolean | isCurrentDateBeforeAndWithinRangeOfDate(Date date, int rangeInDays) Returns whether or not the current date is before and within a given range in days of the passed in date. long difference = date.getTime() - new Date().getTime(); return difference > 0 && difference < TimeUnit.DAYS.toMillis(rangeInDays); |
boolean | isTheSameDayCheckSummerTime(final Date day1, final Date day2, final boolean escapeYear) is The Same Day Check Summer Time final Calendar c = Calendar.getInstance(); c.setTime(day1); final int y = c.get(Calendar.YEAR); final int m = c.get(Calendar.MONTH); final int d = c.get(Calendar.DATE); c.setTime(day2); return (escapeYear || y == c.get(Calendar.YEAR)) && m == c.get(Calendar.MONTH) && d == c.get(Calendar.DATE); |