Jump to content

daylight saving time


NoobLaPHP

Recommended Posts

function updateTimers()
{
    //Get the current timestamp
    now = new Date();
    //Iterate through each of the timers
    for(i=0; i<timers.length; i++)
    {
        //Convert end time to timestamp & calc difference
        endTime = new Date(timers[i].split(' ').join('T'));
        millisecondsDiff = endTime - now;
        //Format the diff and display
        timeDisplay = formatTimeDiff(millisecondsDiff);
        document.getElementById('timer['+i+']').innerHTML = timeDisplay;
    }
}

I'm using the above function to set timers for a page on my website. It should be showing 23 minutes but is showing 83 minutes. This has only come about since the clocks in the UK went forward. Ant help?

 

Link to comment
https://forums.phpfreaks.com/topic/287526-daylight-saving-time/
Share on other sites

i'm guessing (since you didn't show) that the end time comes from some server side code?

 

if so, you are counting on the time zone set on the server being the same as the time zone of the browser displaying these timers. in general, you cannot guarantee that will be the case for any visitor to your site. what you should do instead is treat the time that is output to the browser from the server as a 'delta-time' and initially take the browser's current time and the value being output to it from the server and calculate the end time to be used in the code you posted above to be relative to the browser's current time.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.