Skip to Content

Convert Date into milliseconds example

  1. /*
  2.   Convert Date into milliseconds example
  3.   This example shows how to get the milliseconds since January 1, 1970, 00:00:00 GMT
  4.   represented by this Date object, using getTime() method of java Date class
  5. */
  6.  
  7. import java.util.*;
  8.  
  9. public class ConvertDateIntoMilliSecondsExample{
  10.  
  11.   public static void main(String args[]){
  12.  
  13.   //create a Date object  
  14.   Date date = new Date();
  15.   System.out.println("Date is : " + date);
  16.  
  17.   //use getTime() method to retrieve milliseconds
  18.   System.out.println("Milliseconds since January 1, 1970, 00:00:00 GMT : "
  19.                       + date.getTime());
  20.    
  21.   }
  22.  
  23. }
  24.  
  25. /*
  26. TYPICAL Output would be
  27. Date is : Sun Sep 09 19:56:42 EDT 2007
  28. Milliseconds since January 1, 1970, 00:00:00 GMT : 1189382202606
  29. */