Java Duration Format formatTimeDuration(long timeDuration)

Here you can find the source of formatTimeDuration(long timeDuration)

Description

format Time Duration

License

Apache License

Declaration

public static String formatTimeDuration(long timeDuration) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String formatTimeDuration(long timeDuration) {
        StringBuilder builder = new StringBuilder();
        long hours = timeDuration / (60 * 60 * 1000);
        long mod = (timeDuration % (60 * 60 * 1000));
        long minutes = mod / (60 * 1000);
        mod = mod % (60 * 1000);/* w  ww  .  ja  v a 2s  .  c o  m*/
        long seconds = mod / 1000;
        mod = mod % 1000;
        long ms = mod;

        if (hours != 0) {
            builder.append(hours);
            builder.append(" hrs, ");
        }
        if (minutes != 0) {
            builder.append(minutes);
            builder.append(" mins, ");
        }
        if (seconds != 0) {
            builder.append(seconds);
            builder.append(" sec, ");
        }
        builder.append(ms);
        builder.append(" ms");
        return builder.toString();
    }
}

Related

  1. formatSeconds(Duration duration)
  2. formatShortDuration(long ms)
  3. formattedStringToDuration(final String formattedDuration)
  4. formatTime(long duration)
  5. formatTime(long duration)
  6. formatTS(long duration)
  7. formatWordyDuration(long milliseconds)
  8. PrintDuration(long NanoSeconds)
  9. PrintDurationConciseFromMs(long MilliSeconds)