TimeZone class (the methods of this class was discussed in this article Java.util.TimeZone Class | Set 1) can be used in many cases like using TimeZone class we can get the time difference in term of hour and minute between two places.
Problem : How we can get time difference of time in terms of hours and minutes between two places of Earth?
Solution : To solve above situation, we must follow the following steps
- Get the Time Zone Id as input for both the places.
- Using this Time Zone Id find the Time Zone of both places.
- Using Time Zone Find the Date and Time of both places
- Find the difference between the Date and time of both places
- The difference is your answer for above question
Date and Time of place having Id Asia/Chita Date - 2018-04-25 Time - 04:16 Date and Time of place having Id Asia/Yangon Date - 2018-04-25 Time - 01:46 Difference in Hour is 2 Difference in Minute is 30
Explanation : We are getting TimeZone object of the place using Id provided as Input then using method getDateTime we are getting current Date and Time of that place. The method getDateTime return LocalDateTime object we can get Date using toLocalDate() method of LocalDateTime class and Time using toLocalTime() method of LocalDateTime class.
When we have current date and time of both place then we can find time difference in terms of hour and minute between both places.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Java.util.TimeZone Class | Set 1
- Inner Class And Anonymous Inner Class that Implements Runnable | Concurrent Programming Approach 3
- Implement Octet Class from Septet Class in Java using JavaTuples
- Implement Sextet Class from Quintet Class in Java using JavaTuples
- Implement Quartet Class with Triplet Class in Java using JavaTuples
- Implement Ennead Class from Octet Class in Java using JavaTuples
- Implement Decade Class from Ennead Class in Java using JavaTuples
- Implement Septet Class from Sextet Class in Java using JavaTuples
- Implement Quintet Class with Quartet Class in Java using JavaTuples
- Implement Pair Class with Unit Class in Java using JavaTuples
- Implement Triplet Class with Pair Class in Java using JavaTuples
- Difference between Abstract Class and Concrete Class in Java
- In Java, Can we call the main() method of a class from another class?
- Using predefined class name as Class or Variable name in Java
- Does JVM create object of Main class (the class with main())?
- Java.lang.Class class in Java | Set 2
- Java.lang.Class class in Java | Set 1
- Inner class in java
- JavaFX | Pos Class
- JavaFX | Tab Class
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.