envinyater envinyater - 1 month ago 24
Java Question

Converting an ISO8601 string into DateTime format?

I have a string

20130510T202132Z
that I want to convert into a
DateTime
object.

I've been trying to use Joda to get this to work but I can't get it to work.
I've hit every link I can find on the subject -- and used formatters but it simply isn't working out.

What is the best way to do this?

Answer

Joda Time makes this really easy, as it has built-in support for the ISO format:

DateTimeFormatter iso = ISODateTimeFormat.basicDateTimeNoMillis();
DateTime dateTime = iso.parseDateTime(text);
Comments