Java Utililty Methods TimeUnit Convert

List of utility methods to do TimeUnit Convert

Description

The list of methods to do TimeUnit Convert are organized into topic(s).

Method

doubletoSeconds(long value, TimeUnit unit)
to Seconds
if (unit.ordinal() >= TimeUnit.SECONDS.ordinal()) {
    return TimeUnit.SECONDS.convert(value, unit);
return value / (double) unit.convert(1, TimeUnit.SECONDS);
StringtoSIAbbreviation(final TimeUnit timeUnit)
Return the SI abbreviation from the given TimeUnit name.
if (timeUnit == null) {
    return "";
switch (timeUnit) {
case DAYS:
    return "d";
case HOURS:
    return "h";
...
StringtoString(TimeUnit unit)
to String
switch (unit) {
case HOURS:
case DAYS:
case MINUTES:
case SECONDS:
    return unit.toString().substring(0, 1).toLowerCase();
case MILLISECONDS:
    return "ms";
...
StringtoString(TimeUnit unit)
to String
return names[unit.ordinal()];
longtoTime(final String value, final TimeUnit inputUnit, final TimeUnit outUnit)
toTime.
final String[] parsed = parseTime(value.trim());
return outUnit.convert(Long.parseLong(parsed[0].trim().trim()), unitFor(parsed[1].trim(), inputUnit));
StringtoTimePrecision(final TimeUnit t)
Convert from a TimeUnit to a influxDB timeunit String.
switch (t) {
case HOURS:
    return "h";
case MINUTES:
    return "m";
case SECONDS:
    return "s";
case MILLISECONDS:
...
StringtoTimeUnits(long time)
to Time Units
time = Math.abs(time);
final StringBuilder sb = new StringBuilder(50);
final long days = time / TimeUnit.DAYS.toMillis(1);
if (days > 0) {
    time -= (days * TimeUnit.DAYS.toMillis(1));
    sb.append(days).append("D ");
final long hours = time / TimeUnit.HOURS.toMillis(1);
...