java 这个“YYYY-MM-DD 00:00:00+00:00”是哪种Java日期格式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27313005/
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
Which Java Date format is this "YYYY-MM-DD 00:00:00+00:00"?
提问by Sameervb
I have some data which has date mentioned as "2013-06-30 00:00:00+00:00". I checked the different date formats , however was not able to find this one. Can someone please help ?
我有一些数据提到的日期为“2013-06-30 00:00:00+00:00”。我检查了不同的日期格式,但是找不到这个。有人可以帮忙吗?
回答by MarioDS
This is an ISO 8601formatted date with the T
omitted between the date and time (see: In an ISO 8601 date, is the T character mandatory?)
这是一个ISO 8601格式的日期,T
日期和时间之间省略了(请参阅:在 ISO 8601 日期中,T 字符是否是强制性的?)
回答by Basil Bourque
Optional variation of ISO 8601
ISO 8601 的可选变体
As for your question about "what format" this is, technically this format is an optional variation of ISO 8601. The standard allowsthe T
to be replaced with a SPACE with mutual agreement between the communicating parties.
至于您关于“什么格式”的问题,从技术上讲,这种格式是ISO 8601 的可选变体。该标准允许的T
,以与通信各方之间的协议有一个空格来代替。
The use of a SPACE may make the string more readable by humans where proper numeric-savvy fonts are lacking. But strictly speaking this SPACE version is not standard and so the T
should be included when exchanging data between systems or when serializing data as text.
使用空格可以使字符串更容易被人类在缺乏适当的数字字体的情况下阅读。但严格来说,这个 SPACE 版本不是标准的,因此T
在系统之间交换数据或将数据序列化为文本时应该包括它。
Using java.time
使用 java.time
Other answers are correct. Here is an easy alternative for parsing.
其他答案都是正确的。这是一个简单的解析替代方法。
Your input string nearly complies with the standard ISO 8601formats. Replace the SPACE in the middle with a T
to comply fully.
您的输入字符串几乎符合标准ISO 8601格式。用 a 替换中间的 SPACET
以完全符合。
String input = "2013-06-30 00:00:00+00:00".replace( " " , "T" );
The java.timeclasses supplant the troublesome old legacy date-time classes. These newer classes support ISO 8601 formats by default when parsing/generatihng strings.
该java.time类取代麻烦的旧的遗留日期时间类。这些较新的类在解析/生成字符串时默认支持 ISO 8601 格式。
OffsetDateTime odt = OffsetDateTime.parse( input );
About java.time
关于 java.time
The java.timeframework is built into Java 8 and later. These classes supplant the troublesome old legacydate-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
该java.time框架是建立在Java 8和更高版本。这些类取代了麻烦的旧的遗留日期时间类,例如java.util.Date
, Calendar
, & SimpleDateFormat
。
The Joda-Timeproject, now in maintenance mode, advises migration to the java.timeclasses.
现在处于维护模式的Joda-Time项目建议迁移到java.time类。
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
要了解更多信息,请参阅Oracle 教程。并在 Stack Overflow 上搜索许多示例和解释。规范是JSR 310。
Where to obtain the java.time classes?
从哪里获得 java.time 类?
- Java SE 8and SE 9and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6and SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android
- The ThreeTenABPproject adapts ThreeTen-Backport(mentioned above) for Android specifically.
- See How to use ThreeTenABP….
- Java SE 8和SE 9及更高版本
- 内置。
- 具有捆绑实现的标准 Java API 的一部分。
- Java 9 添加了一些小功能和修复。
- Java SE 6和SE 7
- 多的java.time功能后移植到Java 6和7在ThreeTen-反向移植。
- 安卓
- 所述ThreeTenABP项目适应ThreeTen-反向移植(上述)为Android特异性。
- 请参阅如何使用ThreeTenABP ...。
The ThreeTen-Extraproject extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.
该ThreeTen-额外项目与其他类扩展java.time。该项目是未来可能添加到 java.time 的试验场。你可能在这里找到一些有用的类,比如Interval
,YearWeek
,YearQuarter
,和更多。
回答by Sandeep
I guess it should be YYYY-MM-DD 00:00:00+0000
instead of YYYY-MM-DD 00:00:00+00:00
.
This format is yyyy-MM-dd HH:mm:ss.SSSZ
我想它应该是YYYY-MM-DD 00:00:00+0000
而不是YYYY-MM-DD 00:00:00+00:00
. 这种格式是yyyy-MM-dd HH:mm:ss.SSSZ
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
Date date = new Date();
System.out.println(dateFormat.format(date));
Other different Date formats are
其他不同的日期格式是
yyyy-MM-dd 1969-12-31
yyyy-MM-dd 1970-01-01
yyyy-MM-dd HH:mm 1969-12-31 16:00
yyyy-MM-dd HH:mm 1970-01-01 00:00
yyyy-MM-dd HH:mmZ 1969-12-31 16:00-0800
yyyy-MM-dd HH:mmZ 1970-01-01 00:00+0000
yyyy-MM-dd HH:mm:ss.SSSZ 1969-12-31 16:00:00.000-0800
yyyy-MM-dd HH:mm:ss.SSSZ 1970-01-01 00:00:00.000+0000
yyyy-MM-dd'T'HH:mm:ss.SSSZ 1969-12-31T16:00:00.000-0800
yyyy-MM-dd'T'HH:mm:ss.SSSZ 1970-01-01T00:00:00.000+0000
回答by Mukul Sharma
If you are using java 7+, you can just use X
pattern string for ISO8601 time zone. For your given String, below will work:
如果您使用的是 java 7+,则可以只使用X
ISO8601 时区的模式字符串。对于您给定的字符串,以下将起作用:
LocalDate lt = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssXXX"));