java.time的区域名称的正式列表在哪里? [英] Where is the official list of zone names for java.time?

查看:78
本文介绍了java.time的区域名称的正式列表在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有用于以下用途的区域名称的正式列表:

Is there an official list of zone names that are used for the following:

zoneId = ZoneId.of("America/New_York")

或者java.time.ZoneId是否有可能生成我可以使用的列表本身?

我正在使用它将Instant转换为时间的字符串表示形式,例如:

I'm using this to convert an Instant to a string representation of time like:

ZoneDateTime.ofInstant(instant, zoneId).format(DateTimeFormatter.ofPattern("..."))

推荐答案

只需使用

获取一组可用的区域ID.

Gets the set of available zone IDs.

此集合包括所有可用的基于区域的ID的字符串形式.基于偏移量的区域ID不包含在返回的集中.该ID可以传递给of(String)以创建ZoneId.

This set includes the string form of all available region-based IDs. Offset-based zone IDs are not included in the returned set. The ID can be passed to of(String) to create a ZoneId.

Set<String> zoneIds= ZoneId.getAvailableZoneIds();

for (String zone : zoneIds) {
    System.out.println(zone);
}

这篇关于java.time的区域名称的正式列表在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆