vtokmak vtokmak - 5 months ago 33
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

date time in java to format
dd.MM.yyyy HH:mm
in java?


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.