ADVERTISEMENT
ADVERTISEMENT

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):

  • None

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
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.