You can create an instance of the Date object as follows:
var then = new Date();
You can do one more later:
var now = new Date();
Subtraction gives the difference in milliseconds:
var elapsed = now - then;
(Forcing from "Date" to "Number" is implicit when two date values ββappear on both sides of the subtraction operator. The conversion is similar to calling "now.getTime ()".)
source share