Tutorialspoint

Java Program to get the difference between two time zones

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());
	}
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.