Java: Calculating time zone difference

后端 未结 5 818
野的像风
野的像风 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:29

    Use TimeZone.getRawOffset(): Returns the amount of time in milliseconds to add to UTC to get standard time in this time zone. Because this value is not affected by daylight saving time, it is called raw offset.

    If you want the offset including DST then you use TimeZone.getOffset(long date). You should provide the concrete date to the method, eg now - System.currentTimeMillis()

提交回复
热议问题