• 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

Day Light Saving Offset when to add/substract

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a problem with day light saving time in java, i am able to get time zone offset (i.e, the amount of time by which the clock is forwarded or reversed) but i am not able to get the condition when the clock is forwarded/reversed.

Any help is greatly appreciated.


Thanks in advance
Rohit Sharma
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

So, you want to know for a specific timezone what the rules are for switching from summertime to wintertime and vice versa?

The standard java.util.TimeZone class does not provide that information. In fact, the rules can be quite complicated and differ from year to year - governments around the world are changing timezone rules all the time.

The Joda Time library might help. It has a DateTimeZone class, which as far as I can see also doesn't tell you the exact rules, but it does have methods to get when the next or previous transition was to or from summertime or wintertime.
 
Rohit Shaarma
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jesper, basically my problem is i have a scheduler which runs every day at 12:15PM and due to DST it is running an hour before i.e, at 11:15PM and since as you said TimeZone doesnt provide any rule it is just providing an usigned offset of 1 hour(3600000 msec) what would be the easiest way to handle this issue according to you.




Regards,
Rohit Sharma
 
Rohit Shaarma
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found a simple solution. I just checked whether either current time or scheduled time were in DST, based on that i added/substracted the DST offset. below is a sample code snippet






Regards,
Rohit Sharma
 
Sheriff
Posts: 22791
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of new Date(System.currentTimeMillis()) you can also use new Date(); they are the same thing.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rohit Shaarma wrote:Thank you Jesper, basically my problem is i have a scheduler which runs every day at 12:15PM and due to DST it is running an hour before i.e, at 11:15PM and since as you said TimeZone doesnt provide any rule it is just providing an usigned offset of 1 hour(3600000 msec) what would be the easiest way to handle this issue according to you.


Have your scheduler determine the start time based on java.util.Calendar, rather than java.util.Date. The problem isn't with TimeZone, but rather, I suspect, the fact that your scheduler isn't taking "clock time" into account. And I hate to say it, but your nifty piece of code looks suspiciously like a solution to the symptom, not the problem.

Winston
 
pie. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic