Home > Java > javaTutorial > How to Parse ISO 8601 Dates (e.g., '2011-08-12T20:17:46.384Z') in Java?

How to Parse ISO 8601 Dates (e.g., '2011-08-12T20:17:46.384Z') in Java?

Susan Sarandon
Release: 2024-12-06 09:38:10
Original
839 people have browsed it

How to Parse ISO 8601 Dates (e.g.,

Parsing Dates in ISO 8601 Format

The following question asks about the format of a date string that includes a "T" and a "Z":

I have a date string in the format "2011-08-12T20:17:46.384Z". How can I parse this date in Java?

The "T" is a literal separator between the date and time, and the "Z" denotes "zero hour offset" or "Zulu time" (UTC).

To parse this date string using SimpleDateFormat, you can use the following format string:

SimpleDateFormat format = new SimpleDateFormat(
    "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
Copy after login

Alternatively, you can use Joda Time's ISODateTimeFormat.dateTime() to parse dates in this format.

The above is the detailed content of How to Parse ISO 8601 Dates (e.g., '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