R
Robert Dodier
Hello,
When a string like "2009-06-26 14:13:00-0400" is parsed to
a java.util.Date via java.text.SimpleDateFormat, the timezone
in the string is lost --- the timezone of the result isn't UTC-04:00,
instead it's the default timezone (or date formatter's timezone,
if it was assigned a non-default value).
I could pull off the trailing timezone from the string and parse
it separately and adjust the timezone of the date by hand,
but I can't see a way to do that. java.util.Date doesn't have a
method to change the timezone. java.util.Calendar has
setTimeZone, but the following:
java.util.Date d0 = <whatever>;
java.util.Calendar c = java.util.Calendar.getInstance ();
c.setTime (d0);
c.setTimeZone (<whatever>);
d1 = c.getTime ();
yields a date which has the default timezone.
I can't see another way to do it with Calendar.
Any advice about how to capture the timezone when parsing
a date would be appreciated. Also, if someone wants to
recommend a different time/date library, I would be interested.
Java's built-in time/date functions are a colossal disaster,
but I digress.
best
Robert Dodier
When a string like "2009-06-26 14:13:00-0400" is parsed to
a java.util.Date via java.text.SimpleDateFormat, the timezone
in the string is lost --- the timezone of the result isn't UTC-04:00,
instead it's the default timezone (or date formatter's timezone,
if it was assigned a non-default value).
I could pull off the trailing timezone from the string and parse
it separately and adjust the timezone of the date by hand,
but I can't see a way to do that. java.util.Date doesn't have a
method to change the timezone. java.util.Calendar has
setTimeZone, but the following:
java.util.Date d0 = <whatever>;
java.util.Calendar c = java.util.Calendar.getInstance ();
c.setTime (d0);
c.setTimeZone (<whatever>);
d1 = c.getTime ();
yields a date which has the default timezone.
I can't see another way to do it with Calendar.
Any advice about how to capture the timezone when parsing
a date would be appreciated. Also, if someone wants to
recommend a different time/date library, I would be interested.
Java's built-in time/date functions are a colossal disaster,
but I digress.
best
Robert Dodier