Get current time in Javascript without creating a Date object?

I implement custom double / triple / other clicks in my javascript application, but I am worried about pauses in garbage collection. Is there a way to get the current time accurate to milliseconds without creating a Date object? Some method to reset an existing Date object at the current time?

+4
source share
1 answer

Try using Date.now ()

The now () method returns the milliseconds that have passed since January 1, 1970 00:00:00 UTC so far as a number.

you can use this as a backup for older browsers

if (!Date.now) { Date.now = function now() { return +(new Date); }; } 
+4
source

Source: https://habr.com/ru/post/1439555/


All Articles