Java Time Format formatRuntime(long time, boolean fixedlength)

Here you can find the source of formatRuntime(long time, boolean fixedlength)

Description

Formats the runtime for output

License

Open Source License

Parameter

Parameter Description
time a parameter

Return

the formatted time

Declaration

public static String formatRuntime(long time, boolean fixedlength) 

Method Source Code

//package com.java2s;
/*//from  w ww . j  av a2 s  . co m
 * Copyright (C) 2012 - 2015 Norman Kluge
 * 
 * This file is part of ASGcommon.
 * 
 * ASGcommon is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ASGcommon 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ASGcommon.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Formats the runtime for output
     * @param time
     * @return the formatted time
     */
    public static String formatRuntime(long time, boolean fixedlength) {
        double h_full = ((double) time) / 3600000;
        long h = (long) h_full;
        double min_full = ((h_full - h) * 60);
        long min = (long) min_full;
        double sec_full = ((min_full - min) * 60);
        long sec = (long) sec_full;
        double msec_full = ((sec_full - sec) * 1000);
        long msec = (long) msec_full;

        return ((h == 0) ? (fixedlength ? "     " : "") : String.format("%3d", h) + "h ")
                + ((h == 0 && min == 0) ? (fixedlength ? "       " : "") : String.format("%3d", min) + "min ")
                + ((h == 0 && min == 0 && sec == 0) ? (fixedlength ? "     " : "")
                        : String.format("%3d", sec) + "s ")
                + String.format("%3d", msec) + "ms";
    }
}

Related

  1. formatMusicTime(int time)
  2. formatNanosec(long timeNanosec)
  3. formatPeroid(long time)
  4. formatRemainingTime(float seccounds)
  5. formatRuntime(long runtime)
  6. formatSample(final int aValue, final long aTimestamp)
  7. formatSignificantElapsedTime(final long seconds)
  8. formatStartRowKeyString(String id, String timestampStart)
  9. formatStrDateTime(String stringDateTime)