Home > Java > javaTutorial > body text

How to Parse an ISO-8601 Date String with an Offset Including a Colon in Java?

DDD
Release: 2024-10-30 02:12:02
Original
961 people have browsed it

How to Parse an ISO-8601 Date String with an Offset Including a Colon in Java?

Parsing ISO-8601 Date with Offset Including Colon in Java

Question:

How to parse a date string in the ISO-8601 format with an offset that includes a colon (e.g., "2013-04-03T17:04:39.9430000 03:00") into the "dd.MM.yyyy HH:mm" format in Java?

Answer:

ISO-8601 is a widely used standard date and time format. To parse such a date string in Java, you can utilize the SimpleDateFormat class. Here's how:

<code class="java">SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
DateTime dtIn = inFormat.parse(dateString);  //where dateString is a date in ISO-8601 format

SimpleDateFormat outFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
String dtOut = outFormat.format(dtIn);</code>
Copy after login

This code will convert the ISO-8601 date string into the "dd.MM.yyyy HH:mm" format as specified. If you need to interact with the date as a DateTime object, you can parse it into one using the DateTime class.

The above is the detailed content of How to Parse an ISO-8601 Date String with an Offset Including a Colon 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!