You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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.");
}
}