Here you can find the source of toTimeSpanDescription(long time)
Parameter | Description |
---|---|
time | The time span in milliseconds. |
public static String toTimeSpanDescription(long time)
//package com.java2s; //License from project: Open Source License public class Main { public static final long SECOND_MS = 1000; public static final long MINUTE_MS = SECOND_MS * 60; public static final long HOUR_MS = MINUTE_MS * 60; public static final long DAY_MS = HOUR_MS * 24; /**//ww w .ja va2 s .c o m * @param time The time span in milliseconds. * * @return A human readable description of the time span. */ public static String toTimeSpanDescription(long time) { int days = (int) (time / DAY_MS); time -= days * DAY_MS; int hours = (int) (time / HOUR_MS); time -= hours * HOUR_MS; int minutes = (int) (time / MINUTE_MS); time -= minutes * MINUTE_MS; int seconds = (int) (time / SECOND_MS); time -= seconds * SECOND_MS; int ms = (int) time; if (days != 0) { return days + " days and " + hours + " hours"; } else if (hours != 0) { return hours + " hours and " + minutes + " minutes"; } else if (minutes != 0) { return minutes + " minutes and " + seconds + " seconds"; } else if (seconds != 0) { return seconds + " seconds"; } else { return ms + " ms."; } } }