Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Timezone - PST and PDT

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.
 
Marshal
Posts: 28271
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ritesh and Paul ,
I will check out your suggestions .

Regards ,
-anagha
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic