java get current time in milliseconds

Let’s learn java get current time in milliseconds.

java get current time in milliseconds

To get current time in milliseconds use currentTimeMillis() method of System class.

currentTimeMillis() method returns the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.

Let’s see an example to get current time in milliseconds.

public class CurrentTimeInMilliseconds
{
   public static void main(String[] args) 
   {
      // returning current time in milliseconds
      System.out.println("Current time in milliseconds: " + System.currentTimeMillis());
   }
}


Output:

Current time in milliseconds: 1594902373458


Also read – variables in java