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.
Asked
Active
Viewed 1,896 times
1 Answers
3
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:

Community
- 1
- 1

no.good.at.coding
- 20,221
- 2
- 60
- 51
-
Because I'm targeting single version of embedded browser, I have no need to care about cross-browser issue :) Thanks! – eonil May 17 '11 at 04:18
-
@Eonil The problem isn't really one of cross browser compatibility; I was pointing you to the accuracy (or lack there of) of the time you can get in JavaScript. For example, you may support only IE but you should know that you'll not get times more accurate than 15 ms. Just so you're aware of the potential issues... :) – no.good.at.coding May 17 '11 at 04:44