NoobLaPHP Posted April 4, 2014 Share Posted April 4, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/287526-daylight-saving-time/ Share on other sites More sharing options...
mac_gyver Posted April 5, 2014 Share Posted April 5, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/287526-daylight-saving-time/#findComment-1475040 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.