Java TimeUnit Usage nanosToHMSms(long nanos)

Here you can find the source of nanosToHMSms(long nanos)

Description

nanos To HM Sms

License

Open Source License

Declaration

public static String nanosToHMSms(long nanos) 

Method Source Code

//package com.java2s;

import java.util.concurrent.TimeUnit;

public class Main {
    public static String nanosToHMSms(long nanos) {
        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 micro = TimeUnit.NANOSECONDS.toMicros(in4);
        long nano = in4 - TimeUnit.MICROSECONDS.toNanos(micro);

        return String.format("%dh:%dm:%ds:%dms:%dus:%sns", hour, minute,
                second, milli, micro, nano);
    }/*from w w  w. j  a v a  2  s .  c o  m*/
}

Related

  1. millisToTimeDelta(long millis)
  2. min()
  3. minutesBetween(Date date1, Date date2)
  4. minutesSince(final long startNanos)
  5. nanoElapseToHumanReadable(final Long nanoElapse)
  6. nanosToSecs(long nanos)
  7. nanoToString(final long nanos)
  8. now()
  9. numberOfDaysSinceEpoch(long milliSinceEpoch)