KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What’s the best way to get monotonically increasing time in JavaScript? I’m hoping for something like Java’s System.nanoTime() . Date() obviously won’t work, as it’s affected by system time changes. In other words, what I would like is for a <= b, always : a = myIncreasingTime.getMilliseconds(); ... // some time later, maybe seconds, maybe days b = myIncreasingTime.getMilliseconds(); At best, even when using the UTC functions in Date() , it will return what it believes is the correct time, but if someone sets the time backward, the next call to Date() can return a lesser value. System.nanoTime() does not suffer from this limitation (at least not until the system is rebooted). Modification: [2012-02-26: not intended to affect the original question, which has a bounty] I am not interested knowing the “wall time”, I’m interested in knowing elapsed time with some accuracy, which Date() cannot possibly provide.
Tags (comma-separated)
Save Edits
Cancel