简体   繁体   中英

javascript/timing

我想使用Java脚本计算单击 两个按钮之间的时间差

Here's a hint - use:

var t = Date.now();

to get the current time (measured in milliseconds since 00:00:00 UTC on 01/01/1970) with millisecond resolution .

Note that the result will still be limited in accuracy by the system hardware.

On older browsers without Date.now() , use:

var t = new Date().valueOf();

or the terser

var t = +new Date();

The latter uses numeric coercion (the + prefix) to generate an automatic call to .valueOf() .

  • Get current time from the epoch in milliseconds: new Date().getTime() .
  • Difference between times: endTime - startTime .
  • Show message box: alert("Message") .

Guess these can be combined together as needed.

还可以考虑使用performance.now()获得更高分辨率的时序。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM