Home > Java > javaTutorial > How to Parse the ISO 8601 Date String '2011-08-12T20:17:46.384Z' in Java?

How to Parse the ISO 8601 Date String '2011-08-12T20:17:46.384Z' in Java?

Linda Hamilton
Release: 2024-12-06 15:27:14
Original
310 people have browsed it

How to Parse the ISO 8601 Date String

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");
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template