Java TimeUnit Usage formatElapsedSecs(long secs)

Here you can find the source of formatElapsedSecs(long secs)

Description

Formats an elapsed time in seconds as days, hh:mm:ss.

License

Open Source License

Parameter

Parameter Description
secs Elapsed seconds

Return

A string representation of elapsed time

Declaration

public static String formatElapsedSecs(long secs) 

Method Source Code

//package com.java2s;
/**/* w  w w . j ava2s.co  m*/
 * Oshi (https://github.com/dblock/oshi)
 *
 * Copyright (c) 2010 - 2016 The Oshi Project Team
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Maintainers:
 * dblock[at]dblock[dot]org
 * widdis[at]gmail[dot]com
 * enrico.bianchi[at]gmail[dot]com
 *
 * Contributors:
 * https://github.com/dblock/oshi/graphs/contributors
 */

import java.util.concurrent.TimeUnit;

public class Main {
    /**
     * Formats an elapsed time in seconds as days, hh:mm:ss.
     *
     * @param secs
     *            Elapsed seconds
     * @return A string representation of elapsed time
     */
    public static String formatElapsedSecs(long secs) {
        long eTime = secs;
        final long days = TimeUnit.SECONDS.toDays(eTime);
        eTime -= TimeUnit.DAYS.toSeconds(days);
        final long hr = TimeUnit.SECONDS.toHours(eTime);
        eTime -= TimeUnit.HOURS.toSeconds(hr);
        final long min = TimeUnit.SECONDS.toMinutes(eTime);
        eTime -= TimeUnit.MINUTES.toSeconds(min);
        final long sec = eTime;
        return String.format("%d days, %02d:%02d:%02d", days, hr, min, sec);
    }
}

Related

  1. formatDuration(long millis)
  2. formatDuration(long millis)
  3. formatDuration(long time)
  4. formatDurationSeconds(long seconds)
  5. formatDurationTill(long start)
  6. formatElapsedTime(final long seconds)
  7. formatElapsedTime(long elapsedTimeMs)
  8. formatElapsedTime(long millis)
  9. formatInterval(final long l)