Java Time Format formatTime(long time)

Here you can find the source of formatTime(long time)

Description

formats a long time value into a string of the form 'ddd:hh:mm:ss'

License

Open Source License

Parameter

Parameter Description
time the time value (in milliseconds)

Return

the formatted time string

Declaration

public static String formatTime(long time) 

Method Source Code

//package com.java2s;
/*/*w  ww. j  ava2s  .c o m*/
 * Copyright (c) 2004-2012 The YAWL Foundation. All rights reserved.
 * The YAWL Foundation is a collaboration of individuals and
 * organisations who are committed to improving workflow technology.
 *
 * This file is part of YAWL. YAWL is free software: you can
 * redistribute it and/or modify it under the terms of the GNU Lesser
 * General Public License as published by the Free Software Foundation.
 *
 * YAWL 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 Lesser General
 * Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with YAWL. If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * formats a long time value into a string of the form 'ddd:hh:mm:ss'
     *
     * @param time the time value (in milliseconds)
     * @return the formatted time string
     */
    public static String formatTime(long time) {
        long secsPerHour = 60 * 60;
        long secsPerDay = 24 * secsPerHour;

        long millis = time % 1000;
        time /= 1000;
        long days = time / secsPerDay;
        time %= secsPerDay;
        long hours = time / secsPerHour;
        time %= secsPerHour;
        long mins = time / 60;
        time %= 60;

        return String.format("%d:%02d:%02d:%02d.%04d", days, hours, mins, time, millis);
    }
}

Related

  1. formatTime(long time)
  2. formatTime(long time)
  3. formatTime(long time)
  4. formatTime(long time)
  5. formatTime(long time)
  6. formatTime(long time, String syntax, boolean extraZeros)
  7. formatTime(long timeDiff)
  8. formatTime(long timeDiff)
  9. formatTime(long timeDiffMillis)