programming-examples/java/Servlets_Session_Swing_Util/Compute the difference between two dates.java
2019-11-15 12:59:38 +01:00

22 lines
641 B
Java

Compute the difference between two dates
public class DateDiff {
public static void main(String[] av) {
/** The ending date. This value
* doubles as a Y2K countdown time.
*/
Date d1 = new GregorianCalendar(1999,11,31,23,59).getTime();
/** Today's date */
Date d2 = new Date();
// Get msec from each, and subtract.
long diff = d2.getTime() - d1.getTime();
System.out.println("Difference between " + d2 + "\n" +
"\tand Y2K is " +
(diff / (1000*60*60*24)) +
" days.");
}
}