vtokmak vtokmak - 3 months ago 19
Java Question

Parsing ISO-8601 DateTime in java

I have a trouble with parsing date time in java, I have a strange date time format.
How can I parse

2013-04-03T17:04:39.9430000+03:00
date time in java to format
dd.MM.yyyy HH:mm
in java?

Answer

The "strange" format you're speaking of is actually the ISO-8601 format, which is fairly widely used. You can use SimpleDateFormat to reformat it in most way you please:

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);
//parse it into a DateTime object if you need to interact with it as such

will give you the format you mentioned.