Java 了解具体的UTC时间格式YYYY-MM-DDTHH:MM:SS.SSSZ
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37589693/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Understanding specific UTC time format YYYY-MM-DDTHH:MM:SS.SSSZ
提问by QVSJ
I have two related questions.
我有两个相关的问题。
Assume a program running in BST generates a date time value for current time in UTC YYYY-MM-DDTHH:MM:SS.SSSZ format
假设在 BST 中运行的程序以 UTC YYYY-MM-DDTHH:MM:SS.SSSZ 格式生成当前时间的日期时间值
Also assume current time in London is 2016-06-01 12:33:54
还假设伦敦的当前时间是 2016-06-01 12:33:54
1) if the current time given by the program is 2016-06-01T11:33:54.000Z , is the program wrong?
1) 如果程序给出的当前时间是 2016-06-01T11:33:54.000Z ,是不是程序出错了?
2) how is summer offset for BST is noted in the corresponding time format for YYYY-MM-DDTHH:MM:SS.SSSZ
2) 如何在 YYYY-MM-DDTHH:MM:SS.SSSZ 的相应时间格式中注明 BST 的夏季偏移量
I assume YYYY-MM-DDTHH:MM:SS+0001 Am I correct ?
我假设 YYYY-MM-DDTHH:MM:SS+0001 我正确吗?
采纳答案by vikingsteve
Firstly please have a read of the iso8601 information. It's becoming more common place to deal with times in different time zones (e.g. server time zone and client time zone) and the standard is really useful.
首先请阅读iso8601信息。处理不同时区(例如服务器时区和客户端时区)的时间变得越来越普遍,并且该标准非常有用。
In particular please read about UTC or "Zulu" time here.
特别是请在此处阅读 UTC 或“祖鲁”时间。
1) The program is correct, since the London time is one hour ahead of "UTC" time in summer
1)程序正确,因为伦敦时间比夏季“UTC”时间提前一小时
2) The trailing 'Z' is a short notation for UTC (Zulu). You could also write "+00:00" instead of 'Z'. The SS.SSS refer to seconds and milliseconds - not related to the time zone. In devnull's comment he shows you how to apply an offset for summer.
2) 尾随的“Z”是 UTC(祖鲁语)的缩写。你也可以写“+00:00”而不是“Z”。SS.SSS 指的是秒和毫秒 - 与时区无关。在 devnull 的评论中,他向您展示了如何为夏季应用偏移量。
Edit:
编辑:
There's been some discussion in the comments about whether iso8601 timezone includes timezone or not, and whether timezone will in fact be printed out.
评论中有一些关于iso8601时区是否包含时区以及时区是否会被打印出来的讨论。
This depends completely on the date/time implementation. If we are using SimpleDateFormat
then timezone is supported and will be printed.
这完全取决于日期/时间实现。如果我们正在使用,SimpleDateFormat
则支持时区并将被打印。
Here's a code example to illustrate
这是一个代码示例来说明
SimpleDateFormat formatter = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ss.SSSXXX");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(formatter.format(new Date()));
formatter.setTimeZone(TimeZone.getTimeZone("Europe/London"));
System.out.println(formatter.format(new Date()));
Output
输出
2016-06-02T12:53:14.924Z
2016-06-02T13:53:14.925+01:00
Naturally, if you are using a different date/time library such as joda-time
, then the implentation details will be different.
自然地,如果您使用不同的日期/时间库,例如joda-time
,则实现细节会有所不同。