OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

JavaScript timer (setTimeout) not affected by system time changes

  • Thread starter Thread starter Martin Konecny
  • Start date Start date
M

Martin Konecny

Guest
I've noticed that if I call the JavaScript setTimeout() function with a 1 minute delay, and then change my system time to 5 minutes in the past, the callback function will trigger in 6 minutes.

I did this because I wanted to see what happens during a daylight savings change to the system clock.

My webpage calls setTimeout() to automatically refresh the page every 5 seconds, and if daylight savings were to occur, then the page information would freeze for an hour. Is there a workaround which respects the delay even when such rare changes to the clock occur?

I am updating the page using Ajax, I don't want to refresh the entire page.

<p>I've noticed that if I call <a href="https://developer.mozilla.org/en-US/docs/Web/API/setTimeout" rel="nofollow noreferrer">the JavaScript <code>setTimeout()</code> function</a> with a 1 minute delay, and then change my system time to 5 minutes in the past, the callback function will trigger in 6 minutes.</p>
<p>I did this because I wanted to see what happens during a daylight savings change to the system clock.</p>
<p>My webpage calls <code>setTimeout()</code> to automatically refresh the page every 5 seconds, and if daylight savings were to occur, then the page information would freeze for an hour. Is there a workaround which respects the delay even when such rare changes to the clock occur?</p>
<p>I am updating the page using Ajax, I don't want to refresh the entire page.</p>
 
Top