Last Updated: September 09, 2019
·
711
· abyr

Javascript timestamp

I look for the best performance in my javascript code. And sometimes short sentences looks better and works slower. For example, we have several ways to get timestamp in JavaScript.

And looks like

new Date().getTime()

is almost twice faster then

+new Date()

And the last one is even slower then jQuery "now" function

$.now()

Here are the test on JsPerf

If you works with dates a lot then it makes sense to think of the fastest way.

2 Responses
Add your response

Date.now() is faster when available. Check the edit of the JsPerf. http://jsperf.com/test-the-speed-of-now/3 :)

over 1 year ago ·

Date.now() is the best. Thanks for the good note!

over 1 year ago ·