Java Timestamp getTimeDifference(Timestamp startTime, Timestamp endTime)

Here you can find the source of getTimeDifference(Timestamp startTime, Timestamp endTime)

Description

Gets the time difference.

License

Open Source License

Parameter

Parameter Description
startTime the start time
endTime the end time

Return

the time difference

Declaration

public static String getTimeDifference(Timestamp startTime, Timestamp endTime) 

Method Source Code


//package com.java2s;
import java.sql.Timestamp;

public class Main {
    /**/* w  w w.  ja v a2 s  .  c  om*/
     * Gets the time difference.
     * 
     * @param startTime
     *            the start time
     * @param endTime
     *            the end time
     * @return the time difference
     */
    public static String getTimeDifference(Timestamp startTime, Timestamp endTime) {
        long timeInMilliseconds = endTime.getTime() - startTime.getTime();
        int seconds = (int) (timeInMilliseconds / 1000);
        int minutes = seconds / 60;
        int milliseconds = (int) (timeInMilliseconds % 1000);
        return minutes + " minute(s) " + seconds + " second(s) " + milliseconds + " millisecond(s)";
    }
}

Related

  1. getCurFullTimestampStr()
  2. getCurrTimestamp()
  3. getCurTime2Timestamp()
  4. getCurTimestamp()
  5. getCurTimestamp()
  6. getTimeFromTimestamp( java.sql.Timestamp tsZeitpunkt)
  7. getTimeNanoSec(Timestamp t)
  8. getTimeNextDay(Timestamp date)
  9. getTimeNextMonthFirstSec(Timestamp sysDate)