Here you can find the source of msToHumanReadableDelta(long start)
Parameter | Description |
---|---|
start | The start time of the period of interest. |
public static String msToHumanReadableDelta(long start)
//package com.java2s; //License from project: MIT License import java.util.Formatter; public class Main { /**//from w ww. ja v a 2 s. c om * Write the given timestamp in a 'nice' format (e.g.h 3h4m instead of 188m) * @param start * The start time of the period of interest. * @return A human readable representation of the start time less the time at which the method was called. */ public static String msToHumanReadableDelta(long start) { long stop = System.currentTimeMillis(); return msToHumanReadable(stop - start); } /** * @param ms * The number of milliseconds to parse nicely. * @return A string containing an easily human-readable representation of some number of milliseconds. Best results * for a reasonable number of hours (aka < 24). */ public static String msToHumanReadable(long ms) { if (ms < 1000) { return ms + " ms"; } else if (ms >= 1000 && ms < 60000) { return new Formatter().format("%.2f", ms / 1000f) + " sec"; } else if (ms >= 60000 && ms < 60000 * 60) { long min = ms / 1000 / 60; long sec = (ms - (min * 60000)) / 1000; return min + " min " + sec + " sec"; } else if (ms >= 60000 * 60) { long hours = ms / 1000 / 60 / 60; long min = (ms - hours * 60000 * 60) / 1000 / 60; if (hours > 1) return hours + " hours " + min + " min"; else return hours + " hour " + min + " min"; } else { // This should never happen. return ""; } } }