Java TimeUnit Usage formatTime(long time)

Here you can find the source of formatTime(long time)

Description

format Time

License

Open Source License

Declaration

public static String formatTime(long time) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.concurrent.TimeUnit;

public class Main {
    public static String formatTime(long time) {
        long days = TimeUnit.SECONDS.toDays(time) % 30;
        long hours = TimeUnit.SECONDS.toHours(time) % 24;
        long minutes = TimeUnit.SECONDS.toMinutes(time) % 60;
        long seconds = TimeUnit.SECONDS.toSeconds(time) % 60;

        return (days == 0L) ? String.format("%d hours, %d minutes; and %d seconds", hours, minutes, seconds)
                : String.format("%d days, %d hours, %d minutes; and %d seconds", days, hours, minutes, seconds);
    }/*from w  ww.  j  a v a 2  s  .  c  om*/
}

Related

  1. formatMillisecs(long lMillisecs, final boolean bWantMSecs)
  2. formatMillisIntoMinutesAndSeconds(long millis)
  3. formatMs(long millis)
  4. formatSeconds(int seconds)
  5. formatTime(long time)
  6. formatTime(long timeInNanoseconds)
  7. formatTime(String format, double nanoseconds)
  8. formatTimeDuration(long duration)
  9. formatTimeInMilliSeconds(long duration)