Monotonically increasing time in JavaScript?

后端 未结 4 2031
广开言路
广开言路 2020-12-24 03:08

What’s the best way to get monotonically increasing time in JavaScript? I’m hoping for something like Java’s System.nanoTime().

Date() obvi

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-24 03:30

    You could use window.performance.now() - since Firefox 15, and window.performance.webkitNow() - Chrome 20]

    var a = window.performance.now();
    //...
    var delay = window.performance.now() - a;
    

提交回复
热议问题