有没有办法使用JavaScript获得当前时间(以纳秒为单位)?
问题描述:
所以,我知道我可以使用JavaScript获得当前时间(以毫秒为单位)。但是,是否有可能以纳秒为单位获得当前时间?
So, I know I can get current time in milliseconds using JavaScript. But, is it possible to get the current time in nanoseconds instead?
答
使用以下方法在大多数浏览器中实现微秒精度:
Achieve microsecond accuracy in most browsers using:
window.performance.now()
参见:
- https://developer.mozilla.org/en-US/docs/Web/API/Performance.now()
- http://www.w3.org/TR/hr-time/