5 Replies Latest reply on May 24, 2006 7:23 AM by ogousa-swS9lV

    World times and daylight saving

      I know there's been a bit of talk about this but I haven’t found anything specific for my particular problem. I have designed a website that displays 3 different world times (like a newsroom wall displays the times of certain cities). It was easy enough to get the UTC offset to set these times but then when daylight saving comes into effect I have a problem. I know I need to change the offset but how would I write the code that checks if daylight saving is in effect in that particular zone? (The zones are New York, London and Adelaide (Central Australia)). Any help or direction would be greatly appreciated
        • 1. Re: World times and daylight saving

          Yeah, it would be nice to have some kind of reverse getTimezoneOffset (), but I guess we have to write our own code to adjust for DST here.

          I guess you already know which days and hours the DST shift occurs in your chosen cities. Nevertheless, here are some sites that helped me:

          I have struggled with world clocks just like you. Here's a solution I came up with some time ago.

          myDate = new Date();
          utcYear = myDate.getUTCFullYear();
          utcMonth = myDate.getUTCMonth();
          utcDate = myDate.getUTCDate();
          utcHour = myDate.getUTCHours();

          // -------------------------
          // New York
          // -------------------------
          // NYclock below should be a movieclip or an object defined earlier

          // time zone offset
          NYclock.myOffset = [-5, 0]; // [hours, minutes] (in relation to UTC)
          // hours when the shift occurs
          NYclock.shiftHours = [2,1]; // [DST on, DST off] (hours in local standard time)

          currentClock = NYclock;
          // determine day for shifting into DST (for New York it is the first Sunday of april)
          myDate = new Date();
          monthOn = 3 // april is month 3 (january is 0)
          dayOn = 1;
          while (myDate.getUTCDay()>0) { // Sunday is day 0
          ++dayOn; // count up until we have the first Sunday
          // determine day for shifting from DST (for New York it is the last Sunday of october)
          myDate = new Date();
          monthOff = 9 // october is month 9 (january is 0)
          dayOff = 31;
          while (myDate.getUTCDay()>0) { // Sunday is day 0
          --dayOff; // count down until we have the last Sunday
          // check if we should add time for DST
          presentDate = (utcMonth+1)*100 + utcDate + utcHour/100;
          offShiftHour = -(currentClock.myOffset[0] + currentClock.myOffset[1]/60) + currentClock.shiftHours[1]
          offDate = (monthOff+1)*100 + dayOff + offShiftHour/100;
          onShiftHour = -(currentClock.myOffset[0] + currentClock.myOffset[1]/60) + currentClock.shiftHours[0]
          onDate = (monthOn+1)*100 + dayOn + onShiftHour/100;
          if ((presentDate<offDate) && (presentDate>=onDate)) {
          currentClock.addHour = 1;
          } else {
          currentClock.addHour = 0;


          Hope this helps.
          • 2. Re: World times and daylight saving
            ben_stiller Level 1
            Thanks a million for the help.
            You're a lifesaver!!!
            • 3. Re: World times and daylight saving
              ben_stiller Level 1

              I may have done this wrong but it doesn't seem to be working for me. What I have is a movie clip with a text variable within it that displays the time. I've put the code in the movie clip timeline. Is that correct? Any chance you could send a sample flash file so I could see how it all works? If you can my email is zio.buck@gmail.com
              • 4. Re: World times and daylight saving
                uamg Level 1
                You can put the code in the movie clip timeline. When the code has assigned a value to currentClock.addHour you just have to add this value to the standard time (which I assume you have set earlier) and then display it.
                • 5. Re: World times and daylight saving
                  The uamg's code should work. But if you need to display local time in any country, it will be difficult to go this way. You have to divide the code and the DST rules. The rules should be in array or in external database, and should have formal representation, not like "the first sunday of April", but something like 1,0,3. Also it should contain the start time. The code should check the rules periodically, at least every time you start your program.
                  It is not big deal to calculate local time, using time zone offset. Then you have to check DST for particular country or region and add 1 hour if needed. Or 30 minutes for Lord Howe Island in Australia
                  I use this method for my website Matter of Time. It took a month to find all DST rules and create a database. Also I have to maintain database, because some countries change the rules, for example Israel and Georgia this year.