I want to parse a date that is sent to me like this..
2011-03-02T09:06:07.404-07:00
The problem is when using the SimpleDateFormat object, I get a parse exception and I'm fairly sure its because of the colon in the timezone.
Here is my setup of SimpleDateFormat.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
And here is the list of possible variances in parseable date strings from the developer documentation. As you can see, none of them have a colon in the timezone.
yyyy-MM-dd 1969-12-31
yyyy-MM-dd 1970-01-01
yyyy-MM-dd HH:mm 1969-12-31 16:00
yyyy-MM-dd HH:mm 1970-01-01 00:00
yyyy-MM-dd HH:mmZ 1969-12-31 16:00-0800
yyyy-MM-dd HH:mmZ 1970-01-01 00:00+0000
yyyy-MM-dd HH:mm:ss.SSSZ 1969-12-31 16:00:00.000-0800
yyyy-MM-dd HH:mm:ss.SSSZ 1970-01-01 00:00:00.000+0000
yyyy-MM-dd'T'HH:mm:ss.SSSZ 1969-12-31T16:00:00.000-0800
yyyy-MM-dd'T'HH:mm:ss.SSSZ 1970-01-01T00:00:00.000+0000
My second problem is when I get a date string where the timezone is set to Z. This is the standard for setting a timezone as GMT which is the equivalent of 0000. However I get a ParseException again. Here is an example of the date string.
2011-01-14T10:50:31.520Z
EDIT
Here is how I parse my date string..
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date date = null;
try {
Log.d("CCDateUtilss", "Need to remove the colon from the date string in the timeszone");
date = sdf.parse(string);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return date.getTime();
Possible Solution
Could I just go through and replace the problem occurrences in the String so the it parses properly or is there a more elegant solution I don't know about?
Thanks in advance
Wed Mar 02 16:06:07 GMT+00:00 2011.