Java: Calculating time zone difference

后端 未结 5 815
野的像风
野的像风 2021-02-07 19:07

How do I get the time difference from GMT for a specific date and time zone in Java?

Determining whether a specific time zone is in DST is quite straight-forward:

<
5条回答
  •  梦谈多话
    2021-02-07 19:46

    I suggest to add summer/winter time offset to getRawOffset:

        TimeZone tz1 = TimeZone.getTimeZone("GMT");
        TimeZone tz2 = TimeZone.getTimeZone("America/New_York");
        long timeDifference = tz1.getRawOffset() - tz2.getRawOffset() + tz1.getDSTSavings() - tz2.getDSTSavings();
    

提交回复
热议问题