Home »
Java »
Java Reference »
Java Clock Class
Java Clock Class | getZone() Method with Example
Clock Class getZone() method: Here, we are going to learn about the getZone() method of Clock Class with its syntax and example.
Submitted by Preeti Jain, on May 13, 2020
Clock Class getZone() method
- getZone() method is available in java.time package.
- getZone() method is used to get the time zone that is linked with this Clock.
- getZone() method is a non-static method, it is accessible with the class object and if we try to access the method with the class name then we will get an error.
- getZone() method does not throw an exception at the time of getting time zone.
Syntax:
public abstract ZoneId getZone();
Parameter(s):
Return value:
The return type of this method is ZoneId, it returns the time zone that is used to represent with this Clock.
Example:
// Java program to demonstrate the example
// of getZone() method of Clock
import java.time.*;
public class GetZoneOfClock {
public static void main(String args[]) {
// Initialize two Clock objects
Clock cl1 = Clock.systemDefaultZone();
Clock cl2 = Clock.systemUTC();
// returns the time-zone of this
// Clock cl1
ZoneId cl1_zone = cl1.getZone();
// Display cl1 zone
System.out.println("cl1.getZone(): " + cl1_zone);
// returns the time-zone of this
// Clock cl2
ZoneId cl2_zone = cl2.getZone();
// Display cl2 zone
System.out.println("cl2.getZone(): " + cl2_zone);
}
}
Output
cl1.getZone(): GMT
cl2.getZone(): Z