Decoding the Date Format: 2011-08-12T20:17:46.384Z
Encountering difficulty parsing a date string using Java 1.4's DateFormat may arise from an unknown date format. Understanding the components of this specific format, "2011-08-12T20:17:46.384Z", is crucial for successful parsing.
The date string follows the ISO 8601 standard, which utilizes the letter "T" as a separator between the date and time components. The "Z" suffix indicates "zero hour offset," more commonly known as "Zulu time" or UTC.
To parse this date format, it is recommended to employ SimpleDateFormat. Here's a sample code snippet:
SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); format.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = format.parse("2011-08-12T20:17:46.384Z");
For those utilizing Joda Time, the recommended approach is ISODateTimeFormat.dateTime().
The above is the detailed content of How to Parse the ISO 8601 Date String '2011-08-12T20:17:46.384Z' in Java?. For more information, please follow other related articles on the PHP Chinese website!