Introduction

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

Class declaration

Following is the declaration for java.io.Clock class −

public abstract class Clock
   extends Object

Learn Java in-depth with real-world projects through our Java certification course. Enroll and become a certified expert to boost your career.

Class constructors

Sr.No.Constructor & Description
1protected Clock()This creates a Clock.

Class methods

Sr.No.Method & Description
1boolean equals(Object obj)This method checks if this clock is equal to another clock.
2static Clock fixed(Instant fixedInstant, ZoneId zone)This method obtains a clock that always returns the same instant.
3abstract ZoneId getZone()This method gets the time-zone being used to create dates and times.
4int hashCode()This method gets a hash code for this clock.
5int instant()This method gets the current instant of the clock.
6long millis()This method gets the current millisecond instant of the clock.
7static Clock offset(Clock baseClock, Duration offsetDuration)This method obtains a clock that returns instants from the specified clock with the specified duration added.
8static Clock system(ZoneId zone)This method obtains a clock that returns the current instant using best available system clock.
9static Clock systemDefaultZone()This method obtains a clock that returns the current instant using the best available system clock, converting to date and time using the default time-zone.
10static Clock systemUTC()This method obtains a clock that returns the current instant using the best available system clock, converting to date and time using the UTC time-zone.
11static Clock tick(Clock baseClock, Duration tickDuration)This method obtains a clock that returns instants from the specified clock truncated to the nearest occurrence of the specified duration.
12static Clock tickMinutes(ZoneId zone)This method obtains a clock that returns the current instant ticking in whole minutes using best available system clock.
13static Clock tickSeconds(ZoneId zone)This method obtains a clock that returns the current instant ticking in whole seconds using best available system clock.
14static Clock withZone(ZoneId zone)This method returns a copy of this clock with a different time-zone.

Methods inherited

This class inherits methods from the following classes −

  • Java.lang.Object

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *