【发布时间】:2015-04-07 18:46:46
【问题描述】:
为了获取新加坡的时区偏移量,如果我尝试使用“Singapore”作为 ID,我将得到正确的 ID,如下所示:
TimeZone timeZone = TimeZone.getTimeZone("Singapore");
int offset = timeZone.getRawOffset();//It prints 28800000 which is correct
但是如果如下尝试 SGT 代替新加坡,它将返回 GMT 的偏移量,因为它不将 SGT 理解为 id:
TimeZone timeZone = TimeZone.getTimeZone("SGT");
int offset = timeZone.getRawOffset();//It prints 0 which is incorrect and should be 28800000
有什么方法可以通过使用“SGT”代替“Singapore”来获得正确的新加坡偏移量????
上述问题不适用于 ID“America/Los_Angeles”。 "PST" 和 "America/Los_Angeles" 返回相同的偏移量。
问候
已编辑--
如果我有像“2015-02-08 11:18 AM SGT”这样的日期,那么 ?????
我仍然无法使用上述日期获得“新加坡”的偏移量吗?
试图了解如何使之成为可能。
【问题讨论】:
-
2-4 个字母代码,例如
PST、CST、IST不是真正的时区。 Real time zone 名称的格式为Continent/Region,例如Asia/Singapore。
标签: java timezone timezone-offset