如何管理Java中未直接支持的时区

发布于 2025-01-21 21:49:24 字数 342 浏览 0 评论 0原文

我们通过传递ID字符串 - &gt来获取ZoneID对象。 Zoneid.of(“ US/Alaska”)

在传递位置名称后从Java获取时区ID时,我们会在中获得“ thread” main“ main” java.time.zone中的错误。 Zonerulesexception:未知的时区ID:EST“

我们对多个位置(例如 - > EST,美国/阿根廷,美国/印第安纳州,美国/肯塔基州,美国/North_dakota

处理此类案件的最佳方法是什么?通过传递位置ID获取ZoneID对象是个好主意吗?

we are getting the ZoneId object by passing the id string -> ZoneId.of("US/Alaska")

While getting the timezone ids from java after passing the location name, we get error that "Exception in thread "main" java.time.zone.ZoneRulesException: Unknown time-zone ID: EST"

We get this exception for multiple location like -> EST, America/Argentina, America/Indiana, America/Kentucky, America/North_Dakota

What is the best way to handle such cases? is it good idea to get the ZoneId object by passing location Id?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌面超妹 2025-01-28 21:49:24

您应该指定城市而不是国家(其中大多数是城市),例如阿根廷 的哪个城市?

America/Argentina/Buenos_Aires
America/Argentina/Catamarca
America/Argentina/ComodRivadavia
America/Argentina/...

可以在此处找到有效Java时区的列表( 请参阅评论以获取更好的参考 ):

https:// garygregory。 wordpress.com/2013/06/18/what-are-the-java timezone-ids/


更新:

以获取所有可用区域IDS:

Set<String> zoneIds = ZoneId.getAvailableZoneIds();
System.out.println("Available Zone Ids: \n" + String.join("\n", zoneIds));

You should specify cities not countries (most of them are cities), for example which city of Argentina?

America/Argentina/Buenos_Aires
America/Argentina/Catamarca
America/Argentina/ComodRivadavia
America/Argentina/...

A list of valid Java timezones can be found here (refer to the comments for better reference):

https://garygregory.wordpress.com/2013/06/18/what-are-the-java-timezone-ids/


UPDATE:

In order to get all available zone ids:

Set<String> zoneIds = ZoneId.getAvailableZoneIds();
System.out.println("Available Zone Ids: \n" + String.join("\n", zoneIds));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文