How to measure time in seconds with JavaScript

1 Answer

0 votes
// The JavaScript date is based on a time value that is milliseconds 
// since midnight January 1, 1970, UTC
 
function timeInSeconds() {
    let startTime = Date.now();
 
    for (let i = 0; i < 89000000; i++);
 
    let estimatedTime = (Date.now() - startTime) / 1000; // / 1000 = ms to sec
 
    console.log(estimatedTime);
}
 
timeInSeconds();
 
 
 
/*
run:
 
0.045
 
*/

 



answered Jun 29, 2024 by avibootz
edited Jun 29, 2024 by avibootz
...