On Nov 3, 2008, at 3:30 PM, Julian Reschke wrote:
> Paul Sandoz wrote:
>> ...
>> Jersey defers to a SimpleDateFormat instance for RFC 1123:
>> SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM
>> yyyy HH:mm:ss zzz", Locale.US);
>> TimeZone tz = TimeZone.getTimeZone("GMT");
>> sdf.setTimeZone(tz);
>> GregorianCalendar d = new GregorianCalendar(2003,
>> Calendar.FEBRUARY, 1);
>> System.out.println("toString: " + d.getTime().toString());
>> System.out.println(" format: " + sdf.format(d.getTime()));
>> It looks like the setting of the time zone to GMT causes the date
>> to be formated one day earlier. From the HTTP spec the time zone
>> must be GMT [1]. Is this a bug in the date formatting code?
>> ...
>
> Hmm, is this a trick question? It's just one hour earlier, right?
Doh :-)
>
>
> Doesn't the answer just depend on the time difference between GMT,
> and the VM's default locale (used by GregorianCalendar)?
>
Doh again.
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy
HH:mm:ss zzz", Locale.US);
TimeZone tz = TimeZone.getTimeZone("GMT");
sdf.setTimeZone(tz);
GregorianCalendar d = new GregorianCalendar(2003,
Calendar.FEBRUARY, 1);
d.setTimeZone(tz); // <--- set the time zone here
System.out.println("toString: " + d.getTime().toString());
System.out.println(" format: " + sdf.format(d.getTime()));
which outputs:
toString: Sat Feb 01 01:00:00 CET 2003
format: Sat, 01 Feb 2003 00:00:00 GMT
Thanks for helping out,
Paul.
> BR, Julian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>