javascript - Nodejs getTime() only displays time of execution -


i working in nodejs application running , need current system time every second. problem is displays same time repeatedly rather following system time.

var date = new date(); setinterval(function(){     console.log(date.gettime()); }, 1000); 

this keep returning exact same timestamp every second when need return current system time is, in real time.

well should create new date when function executed. should work:

setinterval(function(){     var date = new date();     console.log(date.gettime()); }, 1000); 

what difference?

well created date before execution of setinterval function. when function executed getting time when object created. in example before calling setinterval function. in example, date object created every time when interval expire , function called.

i hope have helped you.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -