Hello , I am trying to write business logic based on PST and PDT The code runs on a server - whose timezone is changed appropriately as required between : PST & PDT ( As of today it has been changed to PST )
I am trying to figure out when its PST and when its PDT through code.
I am using this code :
However - this code always specifies that the Timezone is PDT i.e above method returns TRUE even though I can see that the server is specifying PST
So I am now using this :
This code works fine .
What is wrong with the code which uses the Timezone class ?
Thanks in advance , -anagha
Joined: Jan 08, 2004
First of all, using getTimezoneOffset() method of java.util.Date object is not advisable as it is a deprecated method.
I am not sure why using TimeZone.getDefault().useDaylightTime() is not working as desired. I have tried sample code in Windows XP machine and tested by changing the date/time settings. For me it worked as desired.
From the API documentation for TimeZone, method useDaylightTime():
"Queries if this time zone uses daylight savings time."
Well, Pacific Time does use daylight saving time. So it will always return you true. If you want to know whether a particular date is in daylight saving time in that time zone then you should use the inDaylightTime(Date) method:
"Queries if the given date is in daylight savings time in this time zone."
Joined: Mar 09, 2005
Thanks Ritesh and Paul , I will check out your suggestions .