• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 6. Date() > Example: Detecting Daylight Savings Time

Example: Detecting Daylight Savings Time

ECMAScript does not by definition include a method of instances of Date() for exposing to developers whether the client is on Daylight Savings Time (DST). The language itself calculates if DST is in effect, but it doesn't tell us directly. I personally think this is an oversight, but a minor one, and easily corrected.

This function uses the Date() constructor function twice: once in January, when DST is never in effect, and once in July, when DST is in effect in every area that supports it. The time zone offsets from UTC (Universal Coordinated Time) for these two instances of Date() can give us a hint as to whether DST is in effect for part of the year. The time zone offset of “now” as compared to the January and July dates can tell us whether DST is in effect “now” if DST is also in effect in one month and not another (see Listing 6.3).


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint