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

qt - QML MouseArea onWheel event not working properly when inside QML Scrollview -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -