Here you can find the source of formatUptime(long startTime)
public static String formatUptime(long startTime)
//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*/ }