Clock systemUTC() Method in Java


The current instance of the clock with the UTC time zone can be obtained using the method systemUTC() in the Clock Class in Java. This method requires no parameters and it returns the current instance of the clock with the UTC time zone.

A program that demonstrates this is given as follows −

Example

 Live Demo

import java.time.*;
public class Demo {
   public static void main(String[] args) {
      Clock c = Clock.systemUTC();
      Instant i = c.instant();
      ZonedDateTime zdt = i.atZone(c.getZone());
      System.out.println(zdt.toString());
   }
}

Output

2019-02-07T08:00:46.924Z

Now let us understand the above program.

The current instance of the clock with the UTC time zone is obtained using the method systemUTC(). Then the ZonedDateTime is printed using the method toString(). A code snippet that demonstrates this is as follows −

Clock c = Clock.systemUTC();
Instant i = c.instant();
ZonedDateTime zdt = i.atZone(c.getZone());
System.out.println(zdt.toString());

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 30-Jul-2019

168 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements