aspose file tools*
The moose likes Beginning Java and the fly likes settimezone on gregorian calendar doesn't work !! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "settimezone on gregorian calendar doesn Watch "settimezone on gregorian calendar doesn New topic
Author

settimezone on gregorian calendar doesn't work !!

samantha clarkson
Ranch Hand

Joined: Sep 09, 2008
Posts: 56
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 .


farm rubbit hihihihihihi, be aware !!
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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:



Steve
 
wood burning stoves
 
subject: settimezone on gregorian calendar doesn't work !!