0

I just want to confirm what I have, I saw on stackoverflow that I can get do the following:

var current_time = +new Date();
console.log (current_time);
var fetch_time = +new Date();
console.log((fetch_time-current_time));

and I now I just want to know what this difference is in. milliseconds?

Log Output
1375976707028
76

I just simply want the fastest way to check if 60 seconds have passed or not. I'd rather avoid any kind of operations like multiplication or division.

Thanks

2 Answers 2

2

The + looks a little weird there, I'd just use .getTime().

.getTime() returns milliseconds, so compare with 60000.

Sign up to request clarification or add additional context in comments.

1 Comment

oh sorry it is confusing
1

try it:

var current_time = +new Date();
var fetch_time;
console.log (current_time);

setTimeout(function() {
    fetch_time = +new Date();
    console.log((fetch_time-current_time)); // 1000 -> ms, 1 -> s
}, 1000);

1 Comment

Thanks! I think I will go with the .getTime and the 6000 check.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.