Java Long Number to Time printExecutionTime(long startTime, long endTime, String className, String methodName)

Here you can find the source of printExecutionTime(long startTime, long endTime, String className, String methodName)

Description

Prints the execution time of a current running method in seconds.

License

Open Source License

Parameter

Parameter Description
startTime Long representing the current System time when the method started.
endTime Long representing the current System time when the method finished.
className The name of the class the method belongs to.
methodName A String containing the name of the current running method.

Declaration

public static void printExecutionTime(long startTime, long endTime, String className, String methodName) 

Method Source Code


//package com.java2s;
/*//w  w  w  .  ja va  2s .  c  o  m
 * Copyright (C) 2016 lefte
 *
 * 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 3 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.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Main {
    /**
     * Prints the execution time of a current running method in seconds.
     * @param startTime Long representing the current System time when the method started.
     * @param endTime Long representing the current System time when the method finished.
     * @param className The name of the class the method belongs to.
     * @param methodName A String containing the name of the current running method.
     */
    public static void printExecutionTime(long startTime, long endTime, String className, String methodName) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Calendar cal = Calendar.getInstance();
        long runningTime = (endTime - startTime) / 1000; //Convert to seconds
        System.err.println("INFO: " + dateFormat.format(cal.getTime()) + " " + className + " " + methodName
                + " run for " + (runningTime == 1 ? runningTime + " second." : runningTime + " seconds."));
    }
}

Related

  1. long2Str(long time)
  2. longToPgnDate(long time)
  3. longToTimedDate(long time)
  4. prettyDate(long time)
  5. printDuration(String message, long startTime)
  6. str2Long(String time)
  7. stringTime(long time)
  8. stringTolong(String time)
  9. time2Date(Long time)