![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 withZone() method in Java
A clock copy of the clock object can be obtained using the method withZone() in Clock Class in Java. This method is used on a clock object to obtain a clock copy. The withZone() method requires a single parameter i.e. the zone that is required to change the time zone. Also, it returns the clock copy of the clock object with the required 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 c1 = Clock.systemDefaultZone(); ZoneId zone = ZoneId.of("Australia/Melbourne"); Clock c2 = c1.withZone(zone); System.out.println("The Zone is: " + c2.getZone()); } }
Output
The Zone is: Australia/Melbourne
Now let us understand the above program.
A clock copy i.e. c2 of the clock object c1 is obtained using the method withZone(). Then the getzone() method is used to print the zone details. A code snippet that demonstrates this is as follows −
Clock c1 = Clock.systemDefaultZone(); ZoneId zone = ZoneId.of("Australia/Melbourne"); Clock c2 = c1.withZone(zone); System.out.println("The Zone is: " + c2.getZone());
Advertisements