Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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". I checked the different date formats , however was not able to find this one. Can someone please help ?

like image 643
Sameervb Avatar asked Dec 05 '14 09:12

Sameervb


3 Answers

Optional variation of ISO 8601

As for your question about "what format" this is, technically this format is an optional variation of ISO 8601. The standard allows the T to be replaced with a SPACE with mutual agreement between the communicating parties.

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.

Using java.time

Other answers are correct. Here is an easy alternative for parsing.

Your input string nearly complies with the standard ISO 8601 formats. Replace the SPACE in the middle with a T to comply fully.

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

The java.time classes supplant the troublesome old legacy date-time classes. These newer classes support ISO 8601 formats by default when parsing/generatihng strings.

OffsetDateTime odt = OffsetDateTime.parse( input );

About java.time

The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.

The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.

To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.

Where to obtain the java.time classes?

  • Java SE 8 and SE 9 and later
    • Built-in.
    • Part of the standard Java API with a bundled implementation.
    • Java 9 adds some minor features and fixes.
  • Java SE 6 and SE 7
    • Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
  • Android
    • The ThreeTenABP project adapts ThreeTen-Backport (mentioned above) for Android specifically.
    • See How to use ThreeTenABP….

The ThreeTen-Extra project 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.

like image 84
Basil Bourque Avatar answered Nov 09 '22 07:11

Basil Bourque


This is an ISO 8601 formatted date with the T omitted between the date and time (see: In an ISO 8601 date, is the T character mandatory?)

like image 41
MarioDS Avatar answered Nov 09 '22 08:11

MarioDS


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

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
like image 2
Sandeep Avatar answered Nov 09 '22 09:11

Sandeep