
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
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());
Advertisements