-->
Skip to main content

Posts

Showing posts with the label Clock

Java Clock class and its Methods with Examples [2021]

Java Clock class and its Methods with Examples [2021]  Java Clock class is one of the java.time package classes introduced in Java 8 which provides access to current instant, date-time using a timezone.  A Clock is a good alternative to old System.currentTimeMillis() and TimeZone.getDefault() methods. Here is the declaration of Java Clock class  public abstract class Clock extends Object The clock is an abstract class it has 4 implementing classes which are shown in below image These four classes FIxedClock, OffsetClock, SystemClock, TickClock implements Clock abstract class. Here is the list of methods that we are going to cover in this tutorial. public abstract Instant instant() public long millis() public abstract ZoneId getZone() public static Clock systemDefaultZone() public static Clock systemUTC() public static Clock system(ZoneId zone) public abstract Clock withZone(ZoneId zone) public static Clock offset(Clock baseClock,Duration offsetDuration) public static Clock fixed(