简体   繁体   English

这个“YYYY-MM-DD 00:00:00+00:00”是哪种Java日期格式?

[英]Which Java Date format is this “YYYY-MM-DD 00:00:00+00:00”?

I have some data which has date mentioned as "2013-06-30 00:00:00+00:00".我有一些数据提到的日期为“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 ?有人可以帮忙吗?

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 .至于您关于“什么格式”的问题,从技术上讲,这种格式是ISO 8601 的可选变体 The standard allows the T to be replaced with a SPACE with mutual agreement between the communicating parties.标准允许在通信双方相互同意的情况下用空格替换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 8601 formats.您的输入字符串几乎符合标准ISO 8601格式。 Replace the SPACE in the middle with a T to comply fully.T替换中间的 SPACE 以完全符合。

String input = "2013-06-30 00:00:00+00:00".replace( " " , "T" );

The java.time classes supplant the troublesome old legacy date-time classes. java.time类取代了麻烦的旧的遗留日期时间类。 These newer classes support ISO 8601 formats by default when parsing/generatihng strings.这些较新的类在解析/生成字符串时默认支持 ISO 8601 格式。

OffsetDateTime odt = OffsetDateTime.parse( input );

About java.time关于 java.time

The java.time framework is built into Java 8 and later. java.time框架内置于 Java 8 及更高版本中。 These classes supplant the troublesome old legacy date-time classes such as java.util.Date , Calendar , & SimpleDateFormat .这些类取代麻烦的老传统日期时间类,如java.util.DateCalendar ,和SimpleDateFormat

The Joda-Time project, now in maintenance mode , advises migration to the java.time classes.现在处于维护模式Joda-Time项目建议迁移到java.time类。

To learn more, see the Oracle Tutorial .要了解更多信息,请参阅Oracle 教程 And search Stack Overflow for many examples and explanations.并在 Stack Overflow 上搜索许多示例和解释。 Specification is JSR 310 .规范是JSR 310

Where to obtain the java.time classes?从哪里获得 java.time 类?

The ThreeTen-Extra project extends java.time with additional classes. ThreeTen-Extra项目用额外的类扩展了 java.time。 This project is a proving ground for possible future additions to java.time.该项目是未来可能添加到 java.time 的试验场。 You may find some useful classes here such as Interval , YearWeek , YearQuarter , and more .您可以在这里找到一些有用的类,比如IntervalYearWeekYearQuarter ,和更多

这是一个ISO 8601格式的日期,在日期和时间之间省略了T (请参阅: 在 ISO 8601 日期中,T 字符是否是强制性的?

I guess it should be YYYY-MM-DD 00:00:00+0000 instead of YYYY-MM-DD 00:00:00+00:00 .我想它应该是YYYY-MM-DD 00:00:00+0000而不是YYYY-MM-DD 00:00:00+00:00 This format is yyyy-MM-dd HH:mm:ss.SSSZ此格式为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

I am adding this answer here because still many people using java 6, 7 in their project.我在这里添加这个答案是因为仍有很多人在他们的项目中使用 java 6、7。

    Calendar cal = new GregorianCalendar();
    try {
        Date paredDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX").parse(s);
        cal.setTime(paredDate);
        return cal;
    } catch (ParseException ex) {
        ex.printStackTrace();
        return null;
    }

You can use above format +OO:OO is for timeZone used您可以使用上述格式 +OO:OO 用于使用的时区

If you are using java 7+, you can just use X pattern string for ISO8601 time zone.如果您使用的是 java 7+,则可以仅对 ISO8601 时区使用X模式字符串。 For your given String, below will work:对于您给定的字符串,以下将起作用:

LocalDate lt = LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssXXX"));

Date and time expressed according to ISO 8601 is for example 2020-10-11T00:00:00+00:00 or 2020-10-11T00:00:00.000+00:00 .根据 ISO 8601 表示的日期和时间是例如2020-10-11T00:00:00+00:002020-10-11T00:00:00.000+00:00

Converting the ISO 8601 to java.util.Date is bit tricky.将 ISO 8601 转换为java.util.Date有点棘手。 We can use the simpleDateformat API of java for the conversion.我们可以使用java的simpleDateformat API进行转换。

sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用日期类获取格式为“ YYYY-MM-DD 00:00:00.0”的数据? - How can i get data in format “YYYY-MM-DD 00:00:00.0” using class Date? java 日期格式将 'M/d/yyyy' 转换为 'yyyy-MM-dd'T'HH:mm:ss.SSSXXX' 就像 2021-04-05T00:00-07:00[UTC-07:00] - java Date format convert 'M/d/yyyy' to 'yyyy-MM-dd'T'HH:mm:ss.SSSXXX' like 2021-04-05T00:00-07:00[UTC-07:00] 格式化2015年6月28日T12:00:00 AM的Java代码为日期格式yyyy-MM-dd'T'HH:mm:ss - java code to format Jun 28, 2015T12:00:00 AM to date format yyyy-MM-dd'T'HH:mm:ss 如何将“2012-03-04 00:00:00.0”转换为日期格式为“dd-mm-yyyy HH:mm:ss”使用Java - How to convert “2012-03-04 00:00:00.0” to Date with Format “dd-mm-yyyy HH:mm:ss” Using Java 如何将 2019 年 10 月 9 日 12:00:00:000AM 的日期字符串格式化为 dd/MM/yyyy - How to format date string of Oct 9 2019 12:00:00:000AM to dd/MM/yyyy 日期转换从12:00:00到00:00:00 java - Date conversion from 12:00:00 to 00:00:00 java TO_DATE ('2020-04-01 00:00:00.0','YYYY-MM-DD HH24:MI:SS.TZR') 中 last.0 的 oracle 格式是什么? - What is oracle format for last .0 in TO_DATE ('2020-04-01 00:00:00.0','YYYY-MM-DD HH24:MI:SS.TZR')? Java - 强制文本字段格式 - UX - 00:00:00;00 - Java - Enforce TextField Format - UX - 00:00:00;00 Java SimpleDateFormat.parse抛出:无法解析的日期:“ 2015-10-06T08:00:00 + 00:00”(偏移量为10) - Java SimpleDateFormat.parse throws : Unparseable date: “2015-10-06T08:00:00+00:00” (at offset 10) 星期五3月30日00:00:00 CET 14到dd / mm / yyyy - Fri Mar 30 00:00:00 CET 14 to dd/mm/yyyy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM