gpt4 book ai didi

java - 时区 ID 夏令时不正确

转载 作者:行者123 更新时间:2023-11-30 11:21:17 24 4
gpt4 key购买 nike

有人能解释一下吗?

TimeZone tz1 = TimeZone.getTimeZone(“CST”); ==> ID of tz1 is CST
TimeZone tz2 = TimeZone.getTimeZone(“CDT”); ==> ID of tz2 is GMT ????

最佳答案

对我来说,下面的测试代码会产生“Not found => CDT”:

for (String tz : TimeZone.getAvailableIDs()) {
if (tz.equals("CDT")) {
System.out.println("Found: " + tz);
}
}

System.out.println("Not found => CDT");

这意味着 java.util.TimeZone 将从不存在的 CDT 区域回退到“GMT”作为 documented :

Returns: the specified TimeZone, or the GMT zone if the given ID cannot be understood.

在 Java 8 中,您可以选择 ZoneId它没有不直观的回退行为,而是抛出一个我认为更好的 ZoneRulesException

关于java - 时区 ID 夏令时不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22310460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com