I am using the following to calculate time elapsed:
var start = new Date();
var end;
var total;
end = new Date();
total = end.getSeconds() - start.getSeconds();
Now this will produce “total” as for example, 8, 4, 14. How can I modify this to give me 4.23, 8.56, 14.12? Do I need to pass something into getSeconds or use a different function?
Use
getTime()instead ofgetSeconds(), it will return the time in milliseconds.Additionally, your method will break if
endis more than one minute ahead ofstart. If you recordstartat, say, 12:30:52 andendat 12:31:01 then you would expecttotalto be 9, but with your code it will be -51.