Java 8 Clock fixed() method with Examples Last Updated : 19 Jun, 2019 Comments Improve Suggest changes Like Article Like Report 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. Syntax: 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. Example: 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 Java // Java program to demonstrate // fixed() method of Clock class import java.time.*; // create class public class fixedMethodDemo { // Main method public static void main(String[] args) { // create instance of clock class Instant instant = Instant.parse("2018-08-19T16:02:42.00Z"); // create ZoneId object for Asia/Calcutta zone ZoneId zoneId = ZoneId.of("Asia/Calcutta"); // call fixed method Clock clock = Clock.fixed(instant, zoneId); // print details of clock System.out.println(clock.toString()); } } Output: FixedClock[2018-08-19T16:02:42Z, Asia/Calcutta] Program 2: Using fixed() for default Zone Java // Java program to demonstrate // fixed() method of Clock class import java.time.*; // create class public class fixedMethodDemo { // Main method public static void main(String[] args) { // create instance of clock class Instant instant = Instant.now(); // create ZoneId for defaultZone which is UTC ZoneId zoneId = ZoneId.systemDefault(); // call fixed method Clock clock = Clock.fixed(instant, zoneId); // print details of clock System.out.println(clock.toString()); } } Output: FixedClock[2018-08-21T08:10:32.498Z, Etc/UTC] Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Clock.html#fixed-java.time.Instant-java.time.ZoneId- Comment More infoAdvertise with us Next Article Java 8 Clock fixed() method with Examples A AmanSingh2210 Follow Improve Article Tags : Java java-basics Java-lang package Java-Functions Java-time package Java-Clock +2 More Practice Tags : Java Similar Reads Java 8 Clock instant() method with Examples 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. instant() method of Clock class returns a current instant of Clock object as Instant Class Object. Instant generates a timestamp to represent machine time. So this method genera 3 min read Java 8 Clock getZone() method with Examples 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.getZone() method of Clock class returns the time-zone used to create dates and times of Clock class. Every Clock class needs a Time Zone for obtaining the current instant of time 2 min read Java 8 Clock hashCode() method with Examples 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. hashCode() method of Clock class returns the hash code for this Clock Object. Clocks object overrides this method based on their state. If clock object is not overridden, the be 2 min read Clock tick() Method in Java with Examples tick(Clock baseClock, Duration tickDuration) method of java.time.Clock is a static method of Clock class that returns a clock that returns instants from the base clock rounded to the nearest occurrence of the specified duration in the parameter. The specified base clock duration must be positive, ne 4 min read Java 8 Clock offset() method with Examples 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. The offset() method is a static method of Clock class which returns a clock with instant equal to the sum of the instants of clock passed as parameter and specific Offset durati 3 min read Java 8 Clock millis() Method with Examples 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.The millis() method of Clock class returns the current instant of the clock in milliseconds. A millisecond instant is measured from 1970-01-01T00:00Z (UTC) to the current time. T 2 min read Java 8 Clock equals() Method with Examples 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.The equals() method of java.time.Clock class checks if two Clock objects are equal or not. If clocks are equal then it returns true, else it returns false. This equals method of 3 min read Clock system() Method in Java with Examples java.time.Clock.system(ZoneId zone) method is a static method of Clock class which returns a clock that returns the current instant of the clock using best available system clock with ZoneID of the returned clock is set to the ZoneID passed. This method can use System.currentTimeMillis(), or other h 3 min read Clock systemUTC() Method in Java with Examples java.time.Clock.systemUTC() method is a static method of Clock class which returns a clock that returns the current instant of the clock using the best available system clock where Zone of the returned clock is UTC time-zone. When the current instant is needed without the date or time, then use syst 2 min read JapaneseDate now(Clock) method in Java with Examples The now() method of java.time.chrono.JapaneseDate class is used to get the current Japanese date according to the Japanese calendar system from the specified clock. Syntax: public static JapaneseDate now(Clock clock) Parameter: This method takes the object of the clock on the basis of which Japanese 2 min read Like