wood burning stoves 2.0*
The moose likes Java in General and the fly likes Short/Long day? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Short/Long day?" Watch "Short/Long day?" New topic

Short/Long day?

Andrew Short

Joined: Feb 13, 2008
Posts: 2
I have a TimeZone:

The daylight savings start on the last Sunday in March at 0100 and finish on the last Sunday in October at 0100.

Given a java.util.Date, how do I find out whether this date is a Long or a Short day?

I suppose basically I am asking is how how do I implement this interface?

Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3003
I would use a Calendar - set it to the same date/time as the Date, then change the time to midnight on that day. Get a new Date to represent that date/time. Then add 1 to the date, so that the Calendar now represents midnight on the next day. Get another Date to represent that date/time. You can then find how much time difference there is between the two using getTime() to convert each Date to milliseconds. Compare this difference to 24 * 60 * 60 * 1000 to see if the difference is more or less than what you'd expect.
Andrew Short

Joined: Feb 13, 2008
Posts: 2
Thanks very much, that works
subject: Short/Long day?
Similar Threads
TimeZone conversion problem
What fields does java.util.Date.equals compare?
date display
Date Function - HOLIDAY
date display