The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
August 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

TimeZone in jdk1.1.8

Posted by Zarko Miloseski on August 23, 2000 at 2:31 AM

Hi,

Could anyone offer any feedback on the following code;

Setting the time zone to be "GMT+10:00" doesn't seem to
reflect the 10 hours in the 'dateString'. I achieve this by
setting the row offset to 10 hours converted in milliseconds.
With jdk1.1.8 it appears that there is a need to set the time
zone and locale to get the correct local time. With jdk1.2
there is no need to deal with timezones and locales. Is there
a better way of this then below in jdk 1.1.8 . What will happen
if some one used the code below in a different time zone.

I did not think hard-coding the timezone and locale is a good
thing.

TimeZone timeZone = TimeZone.getTimeZone("GMT+10:00");
timeZone.setRawOffset(3600*10*1000);
Locale loc = new Locale("en", "AU");
SimpleDateFormat formatter
= new SimpleDateFormat
("dd-MM-yyyy G 'at' hh:mm:ss a zzz", loc);
formatter.setTimeZone(timeZone);
Date currentTime = new Date();
String dateString = formatter.format(currentTime);

Any feedback would be greatly appreciated.

Thanks in advance,
Zarko Miloseski




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us