Java TimeUnit Usage convertMillis(long millis)

Here you can find the source of convertMillis(long millis)

Description

Converts the milli-seconds long into a string.

License

Open Source License

Parameter

Parameter Description
millis the milli-seconds to convert

Return

a string representation of the long value

Declaration

public static String convertMillis(long millis) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.concurrent.TimeUnit;

public class Main {
    /**//from  w  ww  .  j  a  v  a2  s  .  c  o  m
     * Converts the milli-seconds long into a string.
     *
     * @param millis the milli-seconds to convert
     * @return a string representation of the long value
     */
    public static String convertMillis(long millis) {
        String result;
        if (TimeUnit.MILLISECONDS.toHours(millis) != 0L) {
            result = String.format("%d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis),
                    TimeUnit.MILLISECONDS.toMinutes(millis)
                            - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
                    TimeUnit.MILLISECONDS.toSeconds(millis)
                            - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
        } else {
            result = String.format("%d:%02d",
                    TimeUnit.MILLISECONDS.toMinutes(millis)
                            - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
                    TimeUnit.MILLISECONDS.toSeconds(millis)
                            - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
        }
        return result;
    }
}

Related

  1. calculateRuntime(long startTime, long endTime)
  2. calculateTime(final int seconds)
  3. calculateTime(float seconds)
  4. cancelledFuture()
  5. convertMilisecondsToDetail(long ms)
  6. convertMillisecondsToHHMMSS(long milliseconds)
  7. convertNanosecondTimespanToHumanReadableFormat(long aTimespan, boolean aShortFormat, boolean aLongFormat)
  8. convertNanoToSeconds(long nanoTime)
  9. createTimeString(int year, int month, int day, int hours, int minutes, int seconds, String timezoneID)