Here you can find the source of DifferenceInSeconds(Date date1, Date date2)
Parameter | Description |
---|---|
date1 | First date |
date2 | Second date |
public static double DifferenceInSeconds(Date date1, Date date2)
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.util.*; public class Main { /** Finds the difference in seconds between two dates. */*w w w.ja va2 s . co m*/ * @param date1 First date * @param date2 Second date * @return Difference in seconds */ public static double DifferenceInSeconds(Date date1, Date date2) { return DifferenceInMilliseconds(date1, date2) / 1000.0; } private static double DifferenceInMilliseconds(Date date1, Date date2) { return GetTimeInMilliseconds(date1) - GetTimeInMilliseconds(date2); } private static long GetTimeInMilliseconds(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal.getTimeInMillis() + cal.getTimeZone().getOffset(cal.getTimeInMillis()); } }