Here you can find the source of getFormattedDiffTime(long timeFirst, long timeLast)
Parameter | Description |
---|---|
timeFirst | long |
timeLast | long |
public static String getFormattedDiffTime(long timeFirst, long timeLast)
//package com.java2s; //License from project: Apache License import java.util.concurrent.TimeUnit; public class Main { /**//from w w w. j a v a2s . c o m * Format diff time from milliseconds * * @param timeFirst long * @param timeLast long * @return String */ public static String getFormattedDiffTime(long timeFirst, long timeLast) { long timeDiff = timeLast - timeFirst; long ms = timeDiff % 1000; long sec = TimeUnit.MILLISECONDS.toSeconds(timeDiff) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(timeDiff)); long min = TimeUnit.MILLISECONDS.toMinutes(timeDiff); if (min > 29) { return "Time diff > 30m"; } else if (min > 0) { return String.format("%dm %ds %dms", min, sec, ms); } else if (sec > 0) { return String.format("%ds %dms", sec, ms); } else { return String.format("%dms", ms); } } }