Here you can find the source of formatElapsedTime(final long seconds)
Parameter | Description |
---|---|
seconds | Elapsed time in seconds. |
public static String formatElapsedTime(final long seconds)
//package com.java2s; /*//from ww w . j av a 2s . com * Copyright (c) 2014 Cisco Systems, Inc. and others. 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 */ import com.google.common.base.Preconditions; import java.util.concurrent.TimeUnit; public class Main { /** * Formats elapsed time in seconds to form days:hours:minutes:seconds. * * @param seconds Elapsed time in seconds. * @return Formated time as string d:hh:mm:ss */ public static String formatElapsedTime(final long seconds) { Preconditions.checkArgument(seconds >= 0); return String.format("%1d:%02d:%02d:%02d", TimeUnit.SECONDS.toDays(seconds), TimeUnit.SECONDS.toHours(seconds) - TimeUnit.DAYS.toHours(TimeUnit.SECONDS.toDays(seconds)), TimeUnit.SECONDS.toMinutes(seconds) - TimeUnit.HOURS.toMinutes(TimeUnit.SECONDS.toHours(seconds)), seconds - TimeUnit.MINUTES.toSeconds(TimeUnit.SECONDS.toMinutes(seconds))); } }