Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.