- 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
Java Program to get the difference between two time zones by seconds
Here are the two timezones −
ZoneId zone1 = ZoneId.of("America/Panama"); ZoneId zone2 = ZoneId.of("Asia/Taipei");
Set the date −
LocalDateTime dateTime = LocalDateTime.of(2019, 04, 11, 10, 5);
Now, set the first timezone −
ZonedDateTime panamaDateTime = ZonedDateTime.of(dateTime, zone1);
Set the second timezone −
ZonedDateTime taipeiDateTime = panamaDateTime.withZoneSameInstant(zone2);
Get the timezone differences in seconds −
taipeiDateTime.getOffset().getTotalSeconds()
Example
import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; public class Demo { public static void main(String[] args) { ZoneId zone1 = ZoneId.of("America/Panama"); ZoneId zone2 = ZoneId.of("Asia/Taipei"); LocalDateTime dateTime = LocalDateTime.of(2019, 04, 11, 10, 5); ZonedDateTime panamaDateTime = ZonedDateTime.of(dateTime, zone1); ZonedDateTime taipeiDateTime = panamaDateTime.withZoneSameInstant(zone2); System.out.println("Difference between two time zones in seconds = "+taipeiDateTime.getOffset().getTotalSeconds()); } }
Output
Difference between two time zones in seconds = 28800
- Related Articles
- How to get time difference between two timestamps in seconds?
- C# Program to get the difference between two dates in seconds
- Java Program to get Milliseconds between two time instants
- Java Program to get minutes between two time instants
- Java Program to get duration between two time instants
- Java Program to Calculate difference between two Time Periods
- Get the difference between two timestamps in seconds in MySQL?
- How to get the seconds and minutes between two Instant timestamps in Java
- C# Program to get the difference between two dates
- C Program to calculate the difference between two time periods
- C++ Program to Calculate Difference Between Two Time Period
- Golang Program to Calculate Difference Between Two Time Periods
- How to Convert Time Difference between Two Times to Number (Hours/Minutes/Seconds) in Excel?
- Java Program to get Epoch seconds from Instant
- Java Program to get Milli seconds from Instant

Advertisements