| Author |
changing timzone using calender api
|
nancy andrew
Ranch Hand
Joined: Jan 19, 2010
Posts: 30
|
|
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
Bartender
Joined: Sep 08, 2007
Posts: 2926
|
|
|
Use a format in SimpleDateFormat which supports TimeZone.
|
Mohamed Sanaulla | My Blog
|
 |
nancy andrew
Ranch Hand
Joined: Jan 19, 2010
Posts: 30
|
|
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
Bartender
Joined: Sep 08, 2007
Posts: 2926
|
|
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
Joined: Sep 03, 2010
Posts: 7
|
|
I believe you could have set the time zone on the SimpleDateFormat instead of the Calendar object to display correctly.
|
 |
Jacob Anawalt
Greenhorn
Joined: Oct 27, 2010
Posts: 20
|
|
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
|
Jacob
|
 |
 |
|
|
subject: changing timzone using calender api
|
|
|