|
Re: The TimeZone Class
|
Posted: Apr 2, 2004 3:05 AM
|
|
Well, I've done a few tests and the results don't seem illuminating. I do need - TimeZone.setDefault(newZone); - but it doesn't appear to make any difference whether or not I include a timezone in the Calendar.getInstance() method. Resetting to the original default timezone doesn't appear to be necessary once the Timezone objects have gone out of scope (but the setDefault method is static, so I'm not sure of the exact scope, so - to be on the safe side - I'll leave it in). Basically, I think I'll leave the code as is but encapsulate it in a method.Date getTimestamp(String timeZone)
{
TimeZone oldZone = TimeZone.getDefault();
TimeZone newZone = TimeZone.getTimeZone(timeZone);
TimeZone.setDefault(newZone);
Date d = Calendar.getInstance().getTime();
TimeZone.setDefault(oldZone);
return d;
}
It's a kludge based on ignorance, but it passes the tests.
Vince.
|
|