- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 system() Method in Java
The current instance of the clock for the required zoneID can be obtained using the method system() in Clock Class in Java. This method requires a single parameter i.e. the zoneID or the time zone and it returns the current instance of the clock for that time zone.
A program that demonstrates this is given as follows −
Example
import java.time.*; public class Main { public static void main(String[] args) { ZoneId zone = ZoneId.of("Australia/Melbourne"); Clock c = Clock.system(zone); ZonedDateTime zdt = c.instant().atZone(c.getZone()); System.out.println("The Date Time for the given zone is: " + zdt.toString()); } }
Output
The Date Time for the given zone is: 2019-02-06T23:03:16.395+11:00[Australia/Melbourne]
Now let us understand the above program.
The current instance of the clock for the required zoneID is obtained using the method system(). The instant is displayed using the method toString(). A code snippet that demonstrates this is as follows −
ZoneId zone = ZoneId.of("Australia/Melbourne"); Clock c = Clock.system(zone); ZonedDateTime zdt = c.instant().atZone(c.getZone()); System.out.println("The Date Time for the given zone is: " + zdt.toString());
Advertisements