File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Timezone - PST and PDT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Timezone - PST and PDT" Watch "Timezone - PST and PDT" New topic

Timezone - PST and PDT

pendse anagha
Ranch Hand

Joined: Mar 09, 2005
Posts: 44
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 ,
Ritesh Agrawal
Ranch Hand

Joined: Jan 08, 2004
Posts: 74

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.

The Java API docs for java.util.TimeZone getDefault() says

Gets the default TimeZone for this host. The source of the default TimeZone may vary with implementation

Could you please let us know what implementation you are using. I am using Win XP and J2SE 1.5.

Ritesh<br /> <br />SCJP 1.4<br />IBM Test 340<br />IBM AIX V4.0 Certified Professional<br /> <br />Right actions for the future are the best apologies for wrong ones in the past.<br />- Tyron Edwards
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

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."
pendse anagha
Ranch Hand

Joined: Mar 09, 2005
Posts: 44
Thanks Ritesh and Paul ,
I will check out your suggestions .

Regards ,
I agree. Here's the link:
subject: Timezone - PST and PDT
It's not a secret anymore!