Is it Daylight Savings Time?

Asked By Kevin Tipa
30-Oct-09 02:29 PM
Earn up to 0 extra points for answering this tough question.
I recently went through trying to find a way to know for sure if a given javascript Date object had a value that was in daylight savings time or standard time.  I found lots of posts online about finding out the dates for when it occurs, but not one post about finding out if the value in the Date object is in DST or not.  Took me longer than it should have (probably), but I figured out a couple things, and so I'm sharing them here.  I apologize if I'm not supposed to link to other sites, but if you're interested in what I figured out...


I hope that helps if anyone else searches for info on daylight savings time in javascript.

- Kevin

  javascript

Jack jack replied to Kevin Tipa
09-Nov-09 03:58 AM

Date.prototype.stdTimezoneOffset = function() {
var jan = new Date(this.getFullYear(), 0, 1);
var jul = new Date(this.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
}


Date.prototype.dst = function() {
return this.getTimezoneOffset() < this.stdTimezoneOffset();
}

  interesting...

Kevin Tipa replied to Jack jack
09-Nov-09 09:11 AM
Interesting... and you went the extra step to make them extension methods.  Nice.
Create New Account