Here you can find the source of formatUptime(long uptime)
public static String formatUptime(long uptime)
//package com.java2s; /*//from w ww. j ava 2s . com * Copyright (c) 2016, Quancheng-ec.com All right reserved. This software is the * confidential and proprietary information of Quancheng-ec.com ("Confidential * Information"). You shall not disclose such Confidential Information and shall * use it only in accordance with the terms of the license agreement you entered * into with Quancheng-ec.com. */ public class Main { private static final long SECOND = 1000; private static final long MINUTE = 60 * SECOND; private static final long HOUR = 60 * MINUTE; private static final long DAY = 24 * HOUR; public static String formatUptime(long uptime) { StringBuilder buf = new StringBuilder(); if (uptime > DAY) { long days = (uptime - uptime % DAY) / DAY; buf.append(days); buf.append(" Days"); uptime = uptime % DAY; } if (uptime > HOUR) { long hours = (uptime - uptime % HOUR) / HOUR; if (buf.length() > 0) { buf.append(", "); } buf.append(hours); buf.append(" Hours"); uptime = uptime % HOUR; } if (uptime > MINUTE) { long minutes = (uptime - uptime % MINUTE) / MINUTE; if (buf.length() > 0) { buf.append(", "); } buf.append(minutes); buf.append(" Minutes"); uptime = uptime % MINUTE; } if (uptime > SECOND) { long seconds = (uptime - uptime % SECOND) / SECOND; if (buf.length() > 0) { buf.append(", "); } buf.append(seconds); buf.append(" Seconds"); uptime = uptime % SECOND; } if (uptime > 0) { if (buf.length() > 0) { buf.append(", "); } buf.append(uptime); buf.append(" Milliseconds"); } return buf.toString(); } }