There is a really bad problem: setTimeout() is async, but your while loop is blocking. While Daniel posted the right answer to your date problem, you will still have trouble with the async nature. You will not get around that problem, since setTimeout() is coupled with the interpreter's event-loop; something you do not have access to.