Here you can find the source of getDurationFromMillis(final long millis)
Parameter | Description |
---|---|
millis | How long the duration should represent. |
public static String getDurationFromMillis(final long millis)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . j a v a 2 s. c o m * Given a number of milliseconds, calculates a duration string. * * @param millis How long the duration should represent. * @return The duration string. */ public static String getDurationFromMillis(final long millis) { final long seconds = millis / 1000; final long minutes = seconds / 60; if (minutes == 0) { return seconds + "s ago"; } final long hours = minutes / 60; if (hours == 0) { return minutes + "m ago"; } final long days = hours / 24; if (days == 0) { return hours + "h ago"; } return days + "d ago"; } }