• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Gregorian Calendar and time zones

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
CustomID:
GMT Sign Hours : Minutes
GMT Sign Hours Minutes
GMT Sign Hours
Sign: one of
+ -
Hours:
Digit
Digit Digit
Minutes:
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,
Avi.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic