Create Date object

Date()
Creates a Date object and initializes it with the time at which it was allocated.
Date(long date)
Creates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

import java.util.Date;

public class Main{
  public static void main(String args[]) {
    Date date = new Date();

    System.out.println(date);

    long msec = date.getTime();
    System.out.println("Milliseconds since Jan. 1, 1970 GMT=" + msec);
  }
}

The output:


Sat Oct 30 09:10:12 PDT 2010
Milliseconds since Jan. 1, 1970 GMT=1288455012000

Create java Date from specific time


import java.util.Date;

import java.util.Date;

public class Main {
  public static void main(String[] args) {
    Date d = new Date(365L * 24L * 60L * 60L * 1000L+99999999L);
    System.out.println(d);
  }
}

The output:


Fri Jan 01 19:46:39 PST 1971
Home 
  Java Book 
    Essential Classes  

Date:
  1. Date class
  2. Create Date object
  3. Compare two Date value
  4. Convert date value to long value in milliseconds
  5. Convert Date value to String