Alex Rivera | Logout

Performance of Date.now() vs (new Date).getTime()

Asked 2012-09-20T17:00:21.133
172
var timeInMs = Date.now();

per MDN

vs.

var timeInMs = new Date(optional).getTime();

per MDN.

Is there any difference between the two, besides the syntax and the ability to set the Date (to not the current) via optional in the second version?

Date.now() is faster - check out the jsperf

Edit
Report

1 Answer

2

Yes, that is correct; they are effectively equivalent when using the current time.

answered 2012-09-20T17:03:43.550

Your Answer