Here you can find the source of getTimeDifference(Date otherDate)
Parameter | Description |
---|---|
otherDate | - The Date to be used to determine difference in Time between these two points. |
public static long getTimeDifference(Date otherDate)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { /**/*from w w w . j av a2 s .co m*/ * Get the Difference in time From a Date to Now. * * @param otherDate - The Date to be used to determine difference in Time between these two points. * @return long - The Number of Millisecond Difference between a Date and Now in Time. */ public static long getTimeDifference(Date otherDate) { if (otherDate == null) { throw new IllegalArgumentException("Invalid Date Parameter!"); } Calendar now = Calendar.getInstance(); now.setTime(new Date()); Calendar aPointInTime = Calendar.getInstance(); aPointInTime.setTime(otherDate); return aPointInTime.getTimeInMillis() - now.getTimeInMillis(); } /** * Get the Difference in time From a Date to Another Date. * * @param thisDate - A Date referencing a Point in Time. * @param otherDate - The Date to be used to determine difference in Time between these two points. * @return long - The Number of Millisecond Difference between a Date and Now in Time. */ public static long getTimeDifference(Date thisDate, Date otherDate) { if ((thisDate == null) || (otherDate == null)) { throw new IllegalArgumentException("Invalid Date Parameter!"); } Calendar aPointInTime = Calendar.getInstance(); aPointInTime.setTime(thisDate); Calendar anotherPointInTime = Calendar.getInstance(); anotherPointInTime.setTime(otherDate); return aPointInTime.getTimeInMillis() - anotherPointInTime.getTimeInMillis(); } }