• 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

settimezone on gregorian calendar doesn't work !!

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, i have a gregorian calendar, i apply a timezone, then i retrieve the date, but it's displayed in GMT timezone , what can i do for retrieving a date from a calendar with a specified timezone .
After, i have to use a jcalendar which display the time coresponding to the time zone of the server machine.

Code :
TimeZone tz = TimeZone.getTimeZone("America/Caracas");
System.out.println("TZ ID : "+tz.getID());
System.out.println("TZ display name : "+tz.getDisplayName());
GregorianCalendar c = new GregorianCalendar();
c.setTimeZone(tz);
System.out.println("c TZ ID : "+c.getTimeZone().getID());
System.out.println("c TZ display name : "+c.getTimeZone().getDisplayName());
System.out.println("c time : "+c.getTime().toString());

Output :
TZ ID : America/Caracas
TZ display name : Heure du Venezuela
c TZ ID : America/Caracas
c TZ display name : Heure du Venezuela
c time : Sun May 31 13:16:08 GMT 2009


Thanks .
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem isn't that the Calendar's TimeZone isn't working. It is that you are printing the results in your computer's local time zone. You should use a DateFormatter to make sure the date is displayed in the same time zone the Calendar is maintained in:

reply
    Bookmark Topic Watch Topic
  • New Topic