java.time.Clock.systemDefaultZone()
The method Clock.systemDefaultZone() returns a clock that will use the best available system clock to convert instant into date and time using default time-zone.
Method signature
The signature of the java.time.Clock.systemDefaultZone() method is as follows:
public static Clock systemDefaultZone()
The method is available since Java 8.
Parameters
The method takes no parameters.
Return value
Returns a clock that is using the best available system clock in the default time zone, never null.
Exceptions
The method throws no exceptions.
Example usage
In the following code we use java.time.Clock.systemDefaultZone():
package com.farenda.java.time; import java.time.Clock; import java.time.ZoneId; public class ClockExample { public static void main(String[] args) { Clock clock = Clock.systemDefaultZone(); System.out.println("Clock's zone: " + clock.getZone()); System.out.println("System.currentTimeMillis: " + System.currentTimeMillis()); System.out.println("Clock's millis: " + clock.millis()); // It's the same as: Clock sysClock = Clock.system(ZoneId.systemDefault()); System.out.println("System clock's zone: " + sysClock.getZone()); } }
The above code produces the following output:
Clock's zone: Europe/Warsaw System.currentTimeMillis: 1464253352633 Clock's millis: 1464253352633 System clock's zone: Europe/Warsaw