List of utility methods to do TimeUnit Usage
long | minutesSince(final long startNanos) minutes Since return timeSince(startNanos, TimeUnit.MINUTES);
|
String | nanoElapseToHumanReadable(final Long nanoElapse) nano Elapse To Human Readable if (nanoElapse == null) { return "not started"; long nanoElapseLocal = nanoElapse; String elapseFormat = null; final long day = TimeUnit.NANOSECONDS.toDays(nanoElapseLocal); nanoElapseLocal -= TimeUnit.DAYS.toNanos(day); if (day > 0) { ... |
String | nanosToHMSms(long nanos) nanos To HM Sms long hour = TimeUnit.NANOSECONDS.toHours(nanos); long in1 = nanos - TimeUnit.HOURS.toNanos(hour); long minute = TimeUnit.NANOSECONDS.toMinutes(in1); long in2 = in1 - TimeUnit.MINUTES.toNanos(minute); long second = TimeUnit.NANOSECONDS.toSeconds(in2); long in3 = in2 - TimeUnit.SECONDS.toNanos(second); long milli = TimeUnit.NANOSECONDS.toMillis(in3); long in4 = in3 - TimeUnit.MILLISECONDS.toNanos(milli); ... |
long | nanosToSecs(long nanos) nanos To Secs return TimeUnit.NANOSECONDS.toSeconds(nanos);
|
String | nanoToString(final long nanos) nano To String final TimeUnit unit = chooseUnit(nanos); final double value = (double) nanos / NANOSECONDS.convert(1, unit); return String.format("%.4g %s", value, abbreviate(unit)); |
long | now() now Date date = new Date(); long b = TimeUnit.MILLISECONDS.toSeconds(date.getTime()); return b; |
long | numberOfDaysSinceEpoch(long milliSinceEpoch) Returns the number of days since epoch with respect to the given number of milliseconds since epoch. return TimeUnit.MILLISECONDS.toDays(milliSinceEpoch);
|
int | parseDate(String value) parse Date return (int) TimeUnit.MILLISECONDS.toDays(DATE_FORMATTER.parseMillis(value)); |
long | parseDuration(String durationStr) Parses a duration String to its long value. Preconditions.checkArgument(!Strings.isNullOrEmpty(durationStr)); durationStr = durationStr.toLowerCase(); String value = durationStr.substring(0, durationStr.length() - 1); int parsedValue = 0; try { parsedValue = Integer.parseInt(value); } catch (NumberFormatException nfe) { Throwables.propagate(nfe); ... |
long | parseDuration(String text) parse Duration long result = 0; int numIdx = 0; for (int i = 0; i < text.length(); i++) { char at = text.charAt(i); if (at == 'd' || at == 'w' || at == 'm' || at == 'h') { String ns = text.substring(numIdx, i); numIdx = i + 1; if (ns.isEmpty()) { ... |