Java TimeUnit Usage formatUptime(long startTime)

Here you can find the source of formatUptime(long startTime)

Description

format Uptime

License

Apache License

Declaration

public static String formatUptime(long startTime) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.concurrent.TimeUnit;

public class Main {
    public static String formatUptime(long startTime) {
        long seconds = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime);
        final long days = seconds / TimeUnit.DAYS.toSeconds(1);
        seconds -= TimeUnit.DAYS.toSeconds(days);
        final long hours = seconds / TimeUnit.HOURS.toSeconds(1);
        seconds -= TimeUnit.HOURS.toSeconds(hours);
        final long minutes = seconds / TimeUnit.MINUTES.toSeconds(1);
        seconds -= TimeUnit.MINUTES.toSeconds(minutes);
        return String.format("%dd:%dh:%dm:%ds", days, hours, minutes, seconds);
    }/*from  w  ww  . j a  v a2  s .  co m*/
}

Related

  1. formatTime(long time)
  2. formatTime(long timeInNanoseconds)
  3. formatTime(String format, double nanoseconds)
  4. formatTimeDuration(long duration)
  5. formatTimeInMilliSeconds(long duration)
  6. formatUptime(long uptimeInMs)
  7. generateRandomDateTimeForLogEvent(Date laterThan)
  8. getAge(Date birthday)
  9. getAge(long currentTimeMillis, long headerTimestampSec)