Java TimeUnit Usage formatUptime(long uptimeInMs)

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

Description

format Uptime

License

Open Source License

Declaration

public static String formatUptime(long uptimeInMs) 

Method Source Code

//package com.java2s;
/* This file is part of VoltDB.
 * Copyright (C) 2008-2015 VoltDB Inc./*w  w w  .  j  a  v  a  2  s .  co  m*/
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with VoltDB.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.concurrent.TimeUnit;

public class Main {
    public static String formatUptime(long uptimeInMs) {
        long remainingMs = uptimeInMs;
        long days = TimeUnit.MILLISECONDS.toDays(remainingMs);
        remainingMs -= TimeUnit.DAYS.toMillis(days);
        long hours = TimeUnit.MILLISECONDS.toHours(remainingMs);
        remainingMs -= TimeUnit.HOURS.toMillis(hours);
        long minutes = TimeUnit.MILLISECONDS.toMinutes(remainingMs);
        remainingMs -= TimeUnit.MINUTES.toMillis(minutes);
        long seconds = TimeUnit.MILLISECONDS.toSeconds(remainingMs);
        remainingMs -= TimeUnit.SECONDS.toMillis(seconds);
        return String.format("%d days %02d:%02d:%02d.%03d", days, hours, minutes, seconds, remainingMs);
    }
}

Related

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