Reputation:
I want to calculate the time difference between the click of two buttons using java script
Upvotes: 0
Views: 1086
Reputation: 339796
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()
.
Upvotes: 2
Reputation: 32286
new Date().getTime()
.endTime - startTime
.alert("Message")
.Guess these can be combined together as needed.
Upvotes: 1