为什么下面一行打印错误?我认为它应该打印为真。
TimeZone.getTimeZone("UTC+5:30").hasSameRules(TimeZone.getTimeZone("GMT+5:30")
最佳答案
答案在 JavaDoc of TimeZone#getTimeZone 中:
the ID for a TimeZone, either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00"
Returns: the specified TimeZone, or the GMT zone if the given ID cannot be understood.
并且(来自 class documentation )
[...] The syntax of a custom time zone ID is:
CustomID:
GMT Sign Hours : Minutes
GMT Sign Hours Minutes
GMT Sign Hours
ID "UTC+5:30"
不是有效的时区 ID(根据方法/类的规范),被解释为“GMT”时区,这与“GMT+5:30”区域。
关于java - 为什么 GMT 和 UTC 时区没有相同的规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53331858/