Date: diff (Not a method) : Date « java.util « Java by API






Date: diff (Not a method)

/*
The 21st century (up to Thu May 11 14:14:02 PDT 2006) is 1956 days old.
 * */

import java.util.Date;
import java.util.GregorianCalendar;

public class MainClass {

  public static void main(String[] a) throws Exception {
    Date d1 = new GregorianCalendar(2000,11,31,23,59).getTime();

    Date today = new Date();

    long diff = today.getTime() - d1.getTime();

    System.out.println("The 21st century (up to " + today + 
      ") is " + (diff / (1000*60*60*24)) + " days old.");
  }
}


           
       








Related examples in the same category

1.new Date()
2.new Date(int intValue)
3.Date: after(Date when)
4.Date: before(Date when)
5.Date: equals(Object anotherDate)
6.Date: getTime()
7.Date: setTime(long miliseconds)