Here you can find the source of formatRuntime(long time, boolean fixedlength)
Parameter | Description |
---|---|
time | a parameter |
public static String formatRuntime(long time, boolean fixedlength)
//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"; } }