List of utility methods to do TimeUnit Usage
int | getMinutesBetweenDates(Date firstDate, Date secondDate) get Minutes Between Dates long differenceInMillis = secondDate.getTime() - firstDate.getTime(); return (int) TimeUnit.MILLISECONDS.toMinutes(differenceInMillis); |
long | getNormalizedIntervalStartTimestamp(long intervalLengthMillis, long currentTimestamp) get Normalized Interval Start Timestamp long intervalStartTimestamp; if (intervalLengthMillis >= 3600000) { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cal.setTimeInMillis(currentTimestamp); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); intervalStartTimestamp = cal.getTimeInMillis(); ... |
long | getNowInSeconds() Return the current time in seconds. return getNowTimeUnit(TimeUnit.SECONDS);
|
int | getOceanTime(final Date date) Convert the specified date to an Ocean time. return (int) TimeUnit.SECONDS.convert(date.getTime(), TimeUnit.MILLISECONDS) - NO_SECONDS_1970_1980; |
String | getPrettyTime(long duration) get Pretty Time if (duration <= 0) throw new IllegalArgumentException(); return String.format("%02d:%02d:%02d.%03d", TimeUnit.MILLISECONDS.toHours(duration), TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration)), TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)), duration - TimeUnit.SECONDS.toMillis(TimeUnit.MILLISECONDS.toSeconds(duration))); ... |
String | getQuantilesString(final Map get Quantiles String final StringBuilder builder = new StringBuilder(); for (final Entry<Double, Long> entry : quantilesValues.entrySet()) { final String quantile = (entry.getKey() * 100) + " % : " + TimeUnit.NANOSECONDS.toNanos(entry.getValue()) + " ns"; builder.append(quantile); builder.append("\n"); return builder.toString(); ... |
Date | getRandomDate() get Random Date long time = (long) (System.currentTimeMillis() - getRandomDouble() * DAYS.toMillis(3650)); time = time / 1000 * 1000; return new Date(time); |
String | getReadableElapsedIntervalInSeconds(final long elapsedTimInMillis) get Readable Elapsed Interval In Seconds final long hours = TimeUnit.MILLISECONDS.toHours(elapsedTimInMillis); final long minutes = TimeUnit.MILLISECONDS.toMinutes(elapsedTimInMillis - TimeUnit.HOURS.toMillis(hours)); final long seconds = TimeUnit.MILLISECONDS .toSeconds(elapsedTimInMillis - TimeUnit.HOURS.toMillis(hours) - TimeUnit.MINUTES.toMillis(minutes)) + (hours * 60 * 60) + (minutes * 60); final long milliSeconds = TimeUnit.MILLISECONDS.toMillis(elapsedTimInMillis - TimeUnit.HOURS.toMillis(hours) - TimeUnit.MINUTES.toMillis(minutes) - TimeUnit.SECONDS.toMillis(TimeUnit.MILLISECONDS.toSeconds( elapsedTimInMillis - TimeUnit.HOURS.toMillis(hours) - TimeUnit.MINUTES.toMillis(minutes)))); ... |
String | getRemainingTimeString(int completedCount, int totalCount, long elapsed) get Remaining Time String float conceptCountFloat = totalCount; float completedFloat = completedCount; float percentComplete = completedFloat / conceptCountFloat; float estTotalTime = elapsed / percentComplete; long remaining = (long) (estTotalTime - elapsed); String remainingStr = getElapsedTimeString(remaining); return remainingStr; |
double | getSeconds(long time) Return the seconds since the provided time. return (double) TimeUnit.MILLISECONDS.toSeconds(time - System.currentTimeMillis()); |