• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

changing timzone using calender api

 
nancy andrew
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to change timezone to EST (New York) time. But the below code still give me time in GMT. Kindly help me. My code is below
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a format in SimpleDateFormat which supports TimeZone.
 
nancy andrew
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My code started working when i removed the formatter


But i have a question. Calender functionality takes the system date and converts it into a desired format. In case someone alters the system date then program will not give desired results. What can be done so that it takes date , say from internet server or some other place. What changes we need to make to the above code
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code worked because the format specified in the SimpleDateFormat didnt support Timezone information. You need to add "z" at the end of the string passed to SimpleDateFormat for timezone information to be shown.

Please start a new thread for a new question. (There should be some API available, not sure if its in JDK, to get the correct time from the Internet).
 
M Massa
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you could have set the time zone on the SimpleDateFormat instead of the Calendar object to display correctly.

 
Jacob Anawalt
Ranch Hand
Posts: 64
Linux Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setting the formatter's calendar's timezone like that seems cleanest and side-effect free. If you want to use the timezone of a passed calendar, be safe and clone:



This is a pretty good resource for common mistakes with calendars and formatters: http://www.odi.ch/prog/design/datetime.php
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic