views:

445

answers:

4

Hi,

I have a JS date that is being converted by Dojo into RFC822 format. The function call - dojo.date.toRfc3339(jsDate), generates the following date - 2007-02-26T20:15:00+02:00.

I have an application that uses a Java date SimpleDateFormat to parse in the dates generated above. I am having problems parsing this date format due to the timezone. I have attempted to use

yyyy-mm-DD'T'hh:mm:ssZ

This fails as the 'Z' for timezone doesn't expect a ':' character. Does anyone know how I would specify a pattern to handle a RFC822 date with the ':'?

Thanks Jamen

A: 

I'd strip the ':' out of the timezone and use the format you have above.

highlycaffeinated
A: 

This works

SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-DD'T'hh:mm:ssZ");
format.parse("2007-02-26T20:15:00+02:00".replaceAll("([\\+\\-]\\d\\d):(\\d\\d)","$1$2"));

(Note I've taking the final colon out of the format after the 'Z' format specifier.)

mdma
+1  A: 

RFC822 does not allow a colon to be in the time zone portion of date. It expects just the 4 digits. The name of that Dojo method indicates that it is using RFC3339. It seems that is practically the same format as ISO8601. It just so happens that Joda Time has ISODateTimeFormat which is ISO8601 compatible if you are able to use that library. The method dateTimeNoMillis() looks like a match with the Dojo format. It really is nicer than the standard Java date and time API. Otherwise highlycaffeinated's suggestion would be the way to go.

Updated in response to Jamen's update

Isn't there a way to have Dojo use a format that doesn't include the timezone? Then you can adjust the format on the Java side to match. I don't know much about Dojo and I haven't been able to find any documentation on the toRfc3339 function it provides.

laz
A: 

Whoops,

Thanks for correctly interpreting what I am trying to do :) I was meant to say the date is generating in RFC3339 and I needed RFC822. Looks like I will have to override the JavaScript. I was hoping that I wouldn't have to do that and could specify a date format pattern without having to modify any Java Code as the date format is simply injected into a Spring bean of an application.

Just for completeness, is there a way to specify in a date format expression to ignore characters in the sequence (without doing String manipulation/replacement)? In this case I'd be saying ignore any ':' or just ignore the timezone all together?

Thanks Jamen

Jamen
I've never created a question before, but I think you should probably update the original question with this information rather than answer your own question. Just demarcate it as an update using formatting.
laz