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>
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!