添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I have to pass a message (jms) with timezone info like (America/Los_Angeles) but I have only country name and code. If it possible get timezone info with Java code. Somewhere I read this:

System.out.println(TimeZone.getTimeZone("US"));

But its giving output as

sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]

I am expecting List of "America/Los_Angeles", ...

As per the documentation the getTimeZone method returns the specified TimeZone, or the GMT zone if the given ID cannot be understood. There's no TimeZone ID called US hence it gives the GMT zone. If you really want to get all the list of TimeZones available in US, I would suggest you to use the following.

final List timeZonesInUS = Stream.of(TimeZone.getAvailableIDs())

.filter(zoneId -> zoneId.startsWith("US")).collect(Collectors.toList());

I have to pass a message (jms) with timezone info like (America/Los_Angeles) but I have only country name and code. If it possible get timezone info with Java code. Somewhere I read this:System.out.pr... kno zone 软件包的目的是能够在Go 可靠地 使用 IANA 时区 数据库的已知版本。 在Go的时间包 ,LoadLocation方法将搜索多个可能的位置,以找到 时区 数据库,如摘录 所描述的那样,该 时区 来自包的源 代码 。 // The time zone database needed by LoadLocation may not be // present on all systems, especially non-Unix systems. // LoadLocation looks in the directory or uncompressed zip file // named by the ZONE INFO environment variable, if any, then looks in // known installation locations on U
Java 语言 ,您可以通过 java .util.Calendar类取得一个本地时间或者指定 时区 的时间实例,如下: // 取得本地时间: Calendar cal = Calendar.getInstance(); //取得指定 时区 的时间:       Time Zone zone = Time Zone .getTime Zone (“GMT-8:00″); Calendar cal = Calendar
的方法是什么? 答:首先,我们需要在本地或云服务器上安装好Docker,并 获取 到Linux Alpine的最新版镜像。然后,我们可以通过以下步骤来制作 Java 8镜像并配置上海 时区 : 1. 在终端 ,创建一个新的Dockerfile文件: FROM alpine RUN apk update && apk add openjdk8 && \ apk add --no-cache tzdata && \ cp /usr/share/ zone info /Asia/Shanghai /etc/localtime && \ echo "Asia/Shanghai" > /etc/time zone && \ apk del tzdata 2. 在终端 使用 以下命令构建出新的Docker镜像: docker build -t java 8-alpine . 3. 在终端 使用 以下命令启动新的Docker容器: docker run -it java 8-alpine /bin/sh 4. 在终端 ,运行以下命令来验证上海 时区 是否生效: 如果您需要支持 文,您可以再安装一个 文语言包即可。