File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "settimezone on gregorian calendar doesn Watch "settimezone on gregorian calendar doesn New topic

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();
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

Joined: Jan 28, 2003
Posts: 4181

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:

I agree. Here's the link:
subject: settimezone on gregorian calendar doesn't work !!
It's not a secret anymore!