Skip to Content

Get system time using System class

  1. /*
  2.         Get system using System class
  3.         This example shows how to get the system time using currentTimeMillis
  4.         method of Java System class.
  5. */
  6.  
  7. public class GetSystemTime {
  8.  
  9.         public static void main(String[] args) {
  10.                
  11.                 /*
  12.                  * To get system time use,
  13.                  * static long currentTimeMillis() method of
  14.                  * System class.
  15.                  *
  16.                  * This method returns the time in milliseconds since
  17.                  * midnight, January 1, 1970 UTC
  18.                  */
  19.                  
  20.                  long lnSystemTime = System.currentTimeMillis();
  21.                  
  22.                  System.out.println("Milliseconds since midnight, January 1, 1970 UTC : "
  23.                                                                                                                 + lnSystemTime);
  24.         }
  25. }
  26.  
  27. /*
  28.  Output would be system dependent. Typical output would be
  29.  Milliseconds since midnight, January 1, 1970 UTC : 1229529358581
  30. */