So, I know I can get current time in milliseconds using JavaScript. But, is it possible to get the current time in nanoseconds instead?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
No. There is not a chance you will get nanosecond accuracy at the JavaScript layer.
If you're trying to benchmark some very quick operation, put it in a loop that runs it a few thousand times.
JavaScript records time in milliseconds, so you won't be able to get time to that precision. The smart-aleck answer is to "multiply by 1,000,000".
Yes! Try the excellent sazze's nano-time
Building on Jeffery's answer, to get an absolute time-stamp (as the OP wanted) the code would be:
result is in millisecond units but is a floating-point value reportedly "accurate to one thousandth of a millisecond".
Achieve microsecond accuracy in most browsers using:
See also:
In Server side environments like Node.js you can use the following function to get time in nanosecond
Also get micro seconds in a similar way as well: