Convert date value to long value in milliseconds

long getTime()
Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
void setTime(long time)
Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.

Convert Date into milliseconds


import java.util.Date;

public class Main {
  public static void main(String args[]) {
 
    Date date = new Date();
    System.out.println("Date is : " + date);
 
    System.out.println("Milliseconds since January 1, 1970, 00:00:00 GMT : "
        + date.getTime());
  }
}

The output:


Date is : Sat Oct 30 09:17:52 PDT 2010
Milliseconds since January 1, 1970, 00:00:00 GMT : 1288455472578
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