Standard or Daylight Time | JavaScriptSource

Standard or Daylight Time

JavaScriptSource Staff Mar 9, 2007


Is it Standard or Daylight time? This script fills in the correct middle letter of the time zone designation so that either an "S" is shown for Standard, or a "D" for Daylight time. The first function of the script may be used independently if you just need to know in which segment of the year a given date/time is. Adjusted for the new 2007 time changes.

<span class="SorD"></span>


How to use the script:  

1) The first function, SorD, is the one that decides whether a given datetime is in the Standard or Daylight segment of the year. It can be used by itself to make such a decision.

2) The second function, fillSorD, shows one way to use the first function. The datetime of interest is NOW. It can be used to print the middle letter of the time zone designation automatically. For example, on a Web page is the statement, "The cut-off time for the weekly drawing is 5:00 PM CST Saturday." The middle letter of "CST" could be either an "S" or a "D", and this function makes that decision each time the page is loaded.

3) Consequently, the second function must be called when the Web page is loaded. The script includes Simon Willison's Multiple onload function.

4) Put the following code on your page wherever you want the middle letter to appear. You must use a <span> tag (as shown below), but the trade-off is that you can use the script more than once per page if needed.

<span class="SorD"></span>

Source Code

Paste this source code into the designated areas.

External file

Paste this code into an external JavaScript file named: standardDaylightTime.js


Paste this code into your external CSS file or in the <style> section within the HEAD section of your HTML document.


Paste this code into the HEAD section of your HTML document.


Paste this code into the BODY section of your HTML document

Leave a Response


Due to the limitations of these comments, you will need to submit your question to the [a href=""]JavaScript Forum[/a] for further help.

Lee Underwood Jan 29, 2008

Hi,[br /] I have seen your code.. I have an issue with timezone. currently i have timezone offset with me and i have to display the dates which are in UTC on the screen applying the timezoneoffset and Day Light Settings when it is observed..

krishna Dec 13, 2007

Yeesh, how fragile! Doesn't work for anybody outside the US - not only because shifting dates are hardwired into the code, but also because this assumes that your location USES DST, that it's during the middle of the year (~ northern summer), and that the abbreviation uses S and D in this way. What about GMT to BST? CET to CEST? AEST to AEDT? Aargh.

Carl Mar 9, 2007