Connect with one of the following accounts


Please wait while we redirect...

Views: 1031 Ask New Question

How to calculate time difference between two Timezones in Java?

On By

1 Answer

Using following program you can find the difference in two given timezones

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class DifferenceInTimezones {

    public static void main(String[] args) {

        String timeZone1 = "Asia/Kolkata";
        String timeZone2 = "Europe/Paris";

        LocalDateTime dt =;
        ZonedDateTime fromZonedDateTime = dt.atZone(ZoneId.of(timeZone1));
        ZonedDateTime toZonedDateTime = dt.atZone(ZoneId.of(timeZone2));
        long diff = Duration.between(fromZonedDateTime, toZonedDateTime).toMillis();

        System.out.println("difference between timezones is " + diff + " milliseconds");



difference between timezones is 16200000 milliseconds
On By

Answer This Question

Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News