I am fetching data from firebase i need to know how can i check difference between the fetch time and current time
Example
if(this.data.time - current time <= (less or equal) 3 hours) {
console.log('Please wait till difference')
}
What i need if data.time - current time is less then or equal to 3 hours then i need to console the time left in 3 hours.
I have time in second and nanoseconds.
Let me clear more. For example data time is 2.30AM and current time is 3.30AM So its not completed 3 hours till now so i need time left which is 2 hours left. and if time completed like current time is 6.30 so simple console time exceed.
Working with this code but showing error Type 'string' is not assignable to type 'number'.
secondsToHHMMSS(totalSeconds: any): string { // from https://stackoverflow.com/a/1322798/6513921
let hours = Math.floor(totalSeconds / 3600);
totalSeconds %= 3600;
let minutes = Math.floor(totalSeconds / 60);
let seconds = totalSeconds % 60;
// if you want strings with leading zeroes:
minutes = String(minutes).padStart(2, "0"); //here showing error of String
hours = String(hours).padStart(2, "0"); //here showing error of String
seconds = String(seconds).padStart(2, "0"); //here showing error of String
return (hours + ":" + minutes + ":" + seconds);
}
const timeDiff = Math.floor(Date.now() / 1000) - lastLogin.seconds;
if (timeDiff <= 10800) {
console.log('3 hours hasn\'t elapsed yet.');
console.log('Time remaining: ' + this.secondsToHHMMSS(timeDiff));
}