How can I get millisecond resolution (or better) time in HTML5?
-
14-11-2019 - |
سؤال
I'm making HTML5 canvas application. For animation, I need high resolution clock time. How can I get this? It should be millisecond level resolution at minimum.
المحلول
AFAIK, this isn't part of HTML5 but JavaScript. And you can't do this reliably since it depends on the browser implementation. For example, in IE (8 and 6), the smallest resolution you can have is 15 milliseconds.
Update
Apologies - I just noticed you asked how to actually get the time, use Date.getTime()
. This will give you the time in milliseconds since 1st Jan, 1970 but my caveat from above still stands - you'll get a value in milliseconds but you cannot be sure of the accuracy and so you shouldn't depend on this for anything time critical.
References:
لا تنتمي إلى StackOverflow