Java Clock class

The java.time.Clock class providing access to the current instant, date and time using a time-zone.

Java Clock class methods

Method Description
abstract ZoneId getZone() It is used to get the time-zone being used to create dates and times.
abstract Instant instant() It is used to get the current instant of the clock.
static Clock offset(Clock baseClock, Duration offsetDuration) It is used to obtain a clock that returns instants from the specified clock with the specified duration added
static Clock systemDefaultZone() It is used to obtain a clock that returns the current instant using the best available system clock, converting to date and time using the default time-zone.
static Clock systemUTC() It is used to obtain a clock that returns the current instant using the best available system clock, converting to date and time using the UTC time zone.

Example

package com.w3schools;
 
import java.time.Clock;
 
public class TestExample {
	public static void main(String args[]){
		 Clock clock = Clock.systemDefaultZone();      
		 System.out.println(clock.getZone());  
		 System.out.println(clock.instant());    
	}  
}

Output

Asia/Calcutta
2018-04-15T13:35:48.393Z