Javatpoint Logo
Javatpoint Logo

Java Clock class

Java Clock class is used to provide an access to the current instant, date and time using a time zone. It inherits the Object class.


Java Clock class declaration

Let's see the declaration of java.time.Clock class.

Methods of Java Clock

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.

Java Clock class Example: getZone()

Test it Now

Output:

Asia/Calcutta

Java Clock class Example: instant()

Test it Now

Output:

2017-01-14T07:11:07.748Z

Java Clock class Example: systemUTC()

Test it Now

Output:

2017-01-14T07:11:07.748Z

Java Clock class Example: offset()

Test it Now

Output:

2017-01-14T14:15:25.389Z
Next TopicJava ZonedDateTime




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA