permaculture playing cards
The moose likes Java in General and the fly likes Gregorian Calendar and time zones Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Gregorian Calendar and time zones" Watch "Gregorian Calendar and time zones" New topic

Gregorian Calendar and time zones

Mary Taylor
Ranch Hand

Joined: Sep 11, 2000
Posts: 327
Is there a way to tell the GregorianCalendar class to use a Time Zone that is one hour off GMT?
I want to display a clock for a foreign country with its current time. I can get my System time, and I know the offset from GMT for the country in question.
I can get the TimeZone for my location.
Now, how do I change that to GMT plus the offset of the country I am working with?
I've read most of the posts on JavaRanch and am looking at Sun's tutorials.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1141

Hi Betty,
Wouldn't it be easier just to create a SimpleTimeZone for the relevant country (rather than creating a "GMT+1" time zone)?
Is not the country you require listed in the list returned by the "getAvailableIDs()" method in class java.util.TimeZone?
In any case, the javadocs for the "TimeZone" class explain how to set up a "custom" time zone:

If the time zone you want is not represented by
one of the supported IDs, then a custom time
zone ID can be specified to produce a TimeZone.
The syntax of a custom time zone ID is:
GMT Sign Hours : Minutes
GMT Sign Hours Minutes
GMT Sign Hours
Sign: one of
+ -
Digit Digit
Digit Digit
Digit: one of
0 1 2 3 4 5 6 7 8 9
Hours must be between 0 to 23 and Minutes must
be between 00 to 59. For example, "GMT+10"
and "GMT+0010" mean ten hours and ten minutes
ahead of GMT, respectively.

Hope this helps.
Good Luck,
I agree. Here's the link:
subject: Gregorian Calendar and time zones
jQuery in Action, 3rd edition