Java TimeUnit Usage printTimeMap(Map timeMap)

Here you can find the source of printTimeMap(Map timeMap)

Description

print Time Map

License

LGPL

Declaration

public static void printTimeMap(Map<String, Long> timeMap) 

Method Source Code


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

import java.util.Map;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void printTimeMap(Map<String, Long> timeMap) {
        System.out.println(toStringTimeMap(timeMap));
    }/*from  w w  w.  ja v a 2s.co  m*/

    public static String toStringTimeMap(Map<String, Long> timeMap) {
        StringBuilder sb = new StringBuilder();
        for (String stamp : timeMap.keySet()) {
            sb.append(stamp + ": \t" + formatMillis(timeMap.get(stamp)) + "\n");
        }

        return sb.toString();
    }

    public static String formatMillis(long millis) {
        return String.format("%dd:%dh:%dm:%ds:%dms", TimeUnit.MILLISECONDS.toDays(millis),
                TimeUnit.MILLISECONDS.toHours(millis) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(millis)),
                TimeUnit.MILLISECONDS.toMinutes(millis)
                        - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
                TimeUnit.MILLISECONDS.toSeconds(millis)
                        - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)),
                millis - TimeUnit.SECONDS.toMillis(TimeUnit.MILLISECONDS.toSeconds(millis)));
    }
}

Related

  1. parseStringDate(String date)
  2. parseTimeMillis(String timeWithOrWithoutUnit)
  3. parseUntilTime(byte[] untilTime)
  4. pause()
  5. prettyMillis(long mil)
  6. printTimeString(long time)
  7. printTiming(long start, long end)
  8. randomNanos(Random rand, int decimalDigits)
  9. rangeOf(final Date date, final int beforeDates, final int afterDates)