Java Clock Class | systemDefaultZone() Method with Example

Clock Class systemDefaultZone() method: Here, we are going to learn about the systemDefaultZone() method of Clock Class with its syntax and example.
Submitted by Preeti Jain, on May 13, 2020

Clock Class systemDefaultZone() method

  • systemDefaultZone() method is available in java.time package.
  • systemDefaultZone() method is used to get the current instant that uses the system clock in the default zone.
  • systemDefaultZone() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
  • systemDefaultZone() method does not throw an exception at the time of representing Clock.

Syntax:

    public static Clock systemDefaultZone();

Parameter(s):

  • None

Return value:

The return type of this method is Clock, it returns the Clock object that uses the system clock in the default zone.

Example:

// Java program to demonstrate the example 
// of systemDefaultZone() method of Clock

import java.time.*;

public class SystemDefaultZoneOfClock {
    public static void main(String args[]) {
        // Instantiates two ZoneId for Accra 
        ZoneId zone_1 = ZoneId.of("Africa/Accra");

        // Instantiates a clock for
        // the given zone_1 
        Clock cl1 = Clock.system(zone_1);

        // returns a Clock that is available in 
        // the system default zone
        Clock sys_def_zone = cl1.systemDefaultZone();
        System.out.println("cl1.systemDefaultZone(): " + sys_def_zone.toString());

        sys_def_zone = Clock.systemDefaultZone();
        System.out.println("Clock.systemDefaultZone(): " + sys_def_zone.toString());
    }
}

Output

cl1.systemDefaultZone(): SystemClock[GMT]
Clock.systemDefaultZone(): SystemClock[GMT]



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.