3

If i run the following code in google Chrome (Version 40.0.2214.111 m) the system clock accelerates and the system clock goes approx 1-2 second faster every 10 seconds.

I have tested this on a machine running windows 7 64-bit, with intel Atom D525 1.8GHz, 2GB of RAM. All Windows Updates and drivers installed.

setInterval(function(){
   var clientTime = new Date().getTime();
   console.log(clientTime)
},100);

When running the same code in IE, i have no issues with the system time changing.

Anyone else experience the same issue?

http://jsfiddle.net/k4shz7cr/

Update

I added a little test, by using jquery and php to get the time from the webserver (has to be another machine). You can see that the client time changes relative to the webservers time.

following serverTime.php on the webbserver.

<?php
    date_default_timezone_set('Europe/Stockholm');
    $date = microtime(true);
    print $date;
?>

The above (first) JS, changed to:

setInterval(function(){

   $.ajax({
       url: 'serverTime.php',
       type: 'POST',
       success: function( serverTime ){
          var clientTime = new Date().getTime() / 1000;
          var diff = serverTime - clientTime;

          console.log(serverTime,clientTime,diff)
       }
   });

},100);

! the webserver cannot be the same as the client-computer, then the differance will not be showing.

you will always get an differance between servertime and client time because of the execution time of the server code, but the differance would be somewhat constant.

Update 2015-02-17

Now i have tested by installing node and running the same code:

setInterval(function(){
   var clientTime = new Date().getTime();
   console.log(clientTime)
},100);

I get no change UNTIL i open google Chrome, then of a sudden the system time starts to change, not at the same speed as above but a couple seconds per minute. (just starting chrome, nothing else)

This is Insane,

Bilen
  • 65
  • 8
  • 2
    What do you mean by "changing the system clock"? You can't change the OS clock's time by Js. – agoldev Feb 13 '15 at 10:55
  • `setInterval(x, 1234)` does not guarantee that x will be called _precisely_ every 1234ms. – Salman A Feb 13 '15 at 10:59
  • 1
    @SalmanA: Doesn't matter for this question – Bergi Feb 13 '15 at 11:00
  • You found a way to travel in the future :o ... just kidding. Can you create a video of this? Maybe that will clear up this mysterious bug. – Wim Mostmans Feb 13 '15 at 11:00
  • You're right. This is strange. When you take a smaller interval, the effect even gets stronger. (Tested on Win7 64 SP1 with Intel Core i7-2860QM) – Rob Feb 13 '15 at 11:01
  • 1
    Does it by chance also "slow down" the system clock the next second? Remember the pretty clock on the taskbar isn't the _actual_ system clock - it is just another program polling the system time, the same as your fiddle. When lots of things are polling the clock at the same time, or just loads of threads, the response times for the requests get affected. P.S. IE does behave the same – Rhumborl Feb 13 '15 at 11:09
  • 2
    Let me restate: if you are thinking that `clientTime` should increase by 100 then you are mistaken; browser does not guarantee to fire interval/timeout events at precise time (the logged numbers represent milliseconds, not seconds). – Salman A Feb 13 '15 at 11:45
  • @SalmanA, that is not the problem here. – Bilen Feb 13 '15 at 12:20
  • @Rhumborl i added som code to my initial post, hopefully it is a better test of the "bug", even if the clock in the taskbar isnt the actual system clock, by using Date(), i would get the system time not the time showing in the taksbar ? isnt that true? By the new test you can clearly see that there is a difference between the webserver and the client Time (system clock). – Bilen Feb 13 '15 at 12:24
  • Have you tried to observe sys clock without running the script? In my VM on mac (only thing available for me now) I've noticed some "fluctuations" of seconds... but these are independent by script – Luca Rainone Feb 13 '15 at 12:39
  • @chumkiu , Yes there is, but not in this scale, when running the script time changes very rapidly. when closing the tab or browser it emidiately stabilizes again. i also found out that if you first start the code in Safari and then Chrome, you dont get the same effect. – Bilen Feb 13 '15 at 12:47
  • 1
    Well, what is the result that you get and what is the expected result? – Salman A Feb 13 '15 at 20:43
  • @SalmanA the result is that the "gap" between system time and server time gets bigger and bigger while executing code.. Expected would be a more constant difference between the system and client time. – Bilen Feb 14 '15 at 12:08
  • @Bilen Could you please tell us in what way you were observing the accelerating clock in your first example? Were you comparing it against a stopwatch? And as for your second example, it could quite possibly be the case that the browser is unable to keep up with the 10 HTTP requests you are sending every second. – JLRishe Feb 17 '15 at 08:11
  • @JLRishe The clock accelarting is the one in Windows, not the console.log in the browser. In the second example you can use an ordinary stopwatch to get the same result. Write down the System clock time and start both the stopwatch and execute the code. when your stopwatch has elapsed exactly 10 minutes you can se that the system time has changed more than 10 minutes. – Bilen Feb 19 '15 at 13:51
  • I have the same issue, call new Date() in nw.js, will make the system clock more faster, about 10 minutes than standard time in one day. I can not figure out it until now. – iwind Jul 26 '19 at 03:21

0 Answers0