Java Time Format formatElapsedTime(long time)

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

Description

format Elapsed Time

License

Open Source License

Declaration

public static String formatElapsedTime(long time) 

Method Source Code

//package com.java2s;
/* //  w ww  .  j a va2s  .  c o m
 * Copyright (c) 2009-2010, OKTECH-Info Kft. - All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Please check attribution requirements at
 * 
 * http://code.google.com/p/oktech-profiler/wiki/License
 * 
 */

public class Main {
    public static String formatElapsedTime(long time) {
        long ms = time % 1000;
        time = time / 1000;
        long sec = time % 60;
        time = time / 60;
        long min = time % 60;
        time = time / 60;
        long hour = time % 24;
        time = time / 24;
        long day = time;

        StringBuilder sb = new StringBuilder();
        sb.append(day);
        sb.append("d ");
        if (hour < 10)
            sb.append("0");
        sb.append(hour);
        sb.append(":");
        if (min < 10)
            sb.append("0");
        sb.append(min);
        sb.append(":");
        if (sec < 10)
            sb.append("0");
        sb.append(sec);
        sb.append(".");
        if (ms < 100)
            sb.append("0");
        if (ms < 10)
            sb.append("0");
        sb.append(ms);
        return sb.toString();
    }
}

Related

  1. formatDateTime(String value)
  2. formatDateTimeString(final String dateTimeString, final boolean wrapForCodeUsage)
  3. formatDelay(long startTime, long endTime)
  4. formatElapsedTime(int seconds)
  5. formatElapsedTime(long elapsedTime)
  6. formatEndRowKeyString(String id, String timestampEnd)
  7. formatExecutionTime(long executionTime)
  8. formatExecutionTime(long ms)
  9. formatInformalTime(final String minuteRoundedName, final String minuteRoundingToken, final String informalHourName)