I have a strange problem when parsing a ISO8601 date and time with SimpleDateFormat. The relevant code is:
public class DateHelper
{
private static SimpleDateFormat iso8601formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
public static Date parseISO8601(String date) throws ParseException
{
Date result = iso8601formatter.parse(date);
return result;
}
}
For input I'm giving it a string
2010-09-06T15:30:00+02:00
And as a return I get a Date object with date set to 6th of January 2010 with time of 13:30 and timezone of GMT+00:00.
EDIT: I also tried using "2010-09-06T15:30:00+0200" with same results.
Confusing thing is, that the date set is partially correct, just the month is set wrongly.
The issue is shown on Android 1.6 and Android 2.2.
How can I fix it?
Your problem is reproduceable if you use mm
for month instead of MM
.
So I suspect that the cause of the problem is there and that you're not running the version of the code you think you're running. Recompile and reexecute the code as you've in your question. It's correct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With