Java Clock Class | systemUTC() Method with Example

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

Clock Class systemUTC() method

  • systemUTC() method is available in java.time package.
  • systemUTC() method is used to get a Clock that implements the suitable system clock in the UTC zone.
  • systemUTC() 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.
  • systemUTC() method does not throw an exception at the time of representing Clock.

Syntax:

    public static Clock systemUTC();

Parameter(s):

  • None

Return value:

The return type of this method is Clock, it returns the present instant that use the relevant system clock in the UTC zone.

Example:

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

import java.time.*;

public class SystemUTCOfClock {
    public static void main(String args[]) {
        // Instantiates a 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 returns the current
        // instant with help of using the system clock 
        // in the UTC time-zone
        Clock sys_utc_zone = cl1.systemUTC();
        System.out.println("cl1.systemUTC(): " + sys_utc_zone.toString());

        sys_utc_zone = Clock.systemUTC();
        System.out.println("Clock.systemUTC(): " + sys_utc_zone.toString());
    }
}

Output

cl1.systemUTC(): SystemClock[Z]
Clock.systemUTC(): SystemClock[Z]


Comments and Discussions!

Load comments ↻





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