Java Long Number to Time printDuration(String message, long startTime)

Here you can find the source of printDuration(String message, long startTime)

Description

print Duration

License

Open Source License

Declaration

public static void printDuration(String message, long startTime) 

Method Source Code


//package com.java2s;
/*/*from w  w w  .j av  a 2  s  .c  om*/
 * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI for 
 * visualizing and manipulating spatial features with geometry and attributes.
 * Copyright (C) 2012  The JUMP/OpenJUMP contributors
 * 
 * This program 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 2 of the License, or (at your option) 
 * any later version.
 * 
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;

public class Main {
    public static void printDuration(String message, long startTime) {
        String duration = formatDuration(stopDuration(startTime));
        System.out.println(message + ": " + duration + " sec");
    }

    private static String formatDuration(long nanoTime) {
        double seconds = nanoTime / 1.0e9;
        DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.US);
        DecimalFormat formatter = new DecimalFormat("0.000", symbols);
        return formatter.format(seconds);
    }

    public static long stopDuration(long startTime) {
        return System.nanoTime() - startTime;
    }
}

Related

  1. logDuration(Logger logger, Level level, long startTime, String message)
  2. long2Str(long time)
  3. longToPgnDate(long time)
  4. longToTimedDate(long time)
  5. prettyDate(long time)
  6. printExecutionTime(long startTime, long endTime, String className, String methodName)
  7. str2Long(String time)
  8. stringTime(long time)
  9. stringTolong(String time)