What Java date format is "YYYY-MM-DD 00: 00: 00 + 00: 00"?
It is an ISO 8601 formatted date with T
, omitted between date and time (see: Is the T character required in an ISO 8601 date? )
source to share
Additional revision of ISO 8601
As for your question about "what format" it is, technically this format is an optional variant of ISO 8601 . The standard allows to T
replace SPACE with mutual agreement between the communicating parties.
Using SPACE can make the string more readable for people who lack the correct numeric fonts. But, strictly speaking, this version of SPACE is not standard, so T
it should be included when exchanging data between systems or when serializing data as text.
Using java.time
Other answers are correct. Here's a simple alternative for parsing.
Your input string is close to the ISO 8601 standard formats . Replace SPACE in the middle with T
to match perfectly.
String input = "2013-06-30 00:00:00+00:00".replace( " " , "T" );
The java.time classes are supplanting the nasty old obsolete time classes. These new classes support ISO 8601 formats by default when parsing / generating strings.
OffsetDateTime odt = OffsetDateTime.parse( input );
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the nasty old legacy datetime classes such as java.util.Date
, Calendar
and . SimpleDateFormat
The Joda-Time project , now in maintenance mode , advise moving to the java.time classes .
To learn more, see the Oracle Tutorial . And search Stack Overflow for many examples and explanations. Specification JSR 310 .
Where can I get the java.time classes?
- Java SE 8 and SE 9 and later
- Built in.
- Part of the standard Java API with a combined implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and SE 7
- Most of the java.time functionality goes back to Java 6 and 7 in ThreeTen-Backport .
- Android
- The ThreeTenABP project adapts the ThreeTen-Backport (mentioned above) specifically for Android.
- See. How to use ... ThreeTenABP .
The ThreeTen-Extra project extends java.time with additional classes. This project is proof of possible future additions to java.time. Here you can find useful classes, such as Interval
, YearWeek
, YearQuarter
and longer .
source to share
I think it should be YYYY-MM-DD 00:00:00+0000
instead YYYY-MM-DD 00:00:00+00:00
. This formatyyyy-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 miscellaneous date formats:
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
source to share