java.time.Clock.millis() Method Example



Description

The java.time.Clock.millis() method gets the current millisecond instant of the clock.

Declaration

Following is the declaration for java.time.Clock.millis() method.

public long millis()

Return Value

the current millisecond instant from this clock, measured from the Java epoch of 1970-01-01T00:00Z (UTC), not null.

Exception

DateTimeException − if the instant cannot be obtained, not thrown by most implementations.

Example

The following example shows the usage of java.time.Clock.millis() method.

package com.tutorialspoint;

import java.time.Clock;

public class ClockDemo {
   public static void main(String[] args) {
   
      Clock clock = Clock.systemDefaultZone();
      Clock clock1 = Clock.systemUTC();
      System.out.println("Clock 1 millis: " + clock.millis());
      System.out.println("Clock 2 millis: " + clock1.millis());
   }
}

Let us compile and run the above program, this will produce the following result −

Clock 1 millis: 1488867598104
Clock 2 millis: 1488867598104
Advertisements