Java Clock class is part of Date Time API, java.time.Clock, of Java. The Java Date Time API was added from Java version 8.
fixed() method of Clock class returns a clock object and the Clock object returns the same instant. Clock object is returned by calling Clock.fixed(parameters) simply returns the same instant as specified using parameters. The returned class object is immutable, thread-safe and Serializable. The main use of this method is in testing, where the clock needed is fixed in place of the current clock.
public static Clock fixed(Instant fixedInstant, ZoneId zone)
Parameters: This method takes two mandatory parameter:
- fixedInstant – the instant object to create Clock object. It must not be null.
- zone – the time zone for clock object. It must not be null.
Return Value: This method returns Clock object that returns the same instant.
Input:: Instance object as parameter : Instant.parse("2018-08-19T16:45:42.00Z"); TimeZone Object as parameter : ZoneId.of("Asia/Calcutta"); Output:: class object: Explanation:: when Clock.fixed(Instant.parse("2018-08-19T16:45:42.00Z") is called, then the fixed() method will return a clock object in return with fixed time zone and instance.
Below programs illustrates fixed() method of java.time.Clock class:
Program 1: Using fixed() when Zone is defined
Program 2: Using fixed() for default Zone
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Android | How to display Analog clock and Digital clock
- Java Clock tickMinutes() method in Java with Examples
- Java Clock withZone() method in Java with Examples
- Java 8 Clock instant() method with Examples
- Java 8 Clock hashCode() method with Examples
- Java 8 Clock getZone() method with Examples
- Java 8 Clock millis() Method with Examples
- Java 8 Clock equals() Method with Examples
- Java 8 Clock offset() method with Examples
- Clock tick() Method in Java with Examples
- Clock tickSeconds() method in Java with Examples
- Clock systemDefaultZone() Method in Java with Examples
- Clock systemUTC() Method in Java with Examples
- Clock system() Method in Java with Examples
- JapaneseDate now(Clock) method in Java with Examples
- YearMonth now(clock) method in Java with Examples
- LocalTime now(clock) method in Java with Examples
- MonthDay now(Clock) method in Java with Examples
- HijrahChronology dateNow(Clock) method in Java with Example
- HijrahDate now(Clock) method in Java with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet