Here you can find the source of formatWordyDuration(long milliseconds)
Parameter | Description |
---|---|
milliseconds | Time duration in milliseconds |
public static String formatWordyDuration(long milliseconds)
//package com.java2s; /* Please see the license information at the end of this file. */ public class Main { /** Format a wordy time duration (e.g., "5 days, 3 hours, 23 minutes"). */*from ww w . j av a 2 s . c o m*/ * @param milliseconds Time duration in milliseconds * * @return Formated time duration. */ public static String formatWordyDuration(long milliseconds) { long seconds = milliseconds / 1000; long days = seconds / 86400; seconds -= days * 86400; long hours = seconds / 3600; seconds -= hours * 3600; long minutes = seconds / 60; seconds -= minutes * 60; StringBuffer buf = new StringBuffer(); if (days > 0) buf.append(days + (days == 1 ? " day, " : " days, ")); if (days > 0 || hours > 0) buf.append(hours + (hours == 1 ? " hour, " : " hours, ")); buf.append(minutes + (minutes == 1 ? " minute" : " minutes")); return buf.toString(); } }