I want to run a function in a specific time, and found a solution here :Call a javascript function at a specific time of day
Code:
var now = new Date();
var threepm = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 3, 0) - now;
var twelveam = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 1) - now;
if (threepm < 0) {
threepm += 86400000; // it's after 3PM, try 3PM tomorrow.
}setTimeout(threeamfunction, threepm);
But it doesnt work, so I tried printing both now and threepm without deducting the current time.
New Code:
var now = new Date();
var threepm = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 3, 0);
console.log(now);
console.log(threepm);
And I found out that both times aren't the same.
Result of the log is
2020-05-05T19:26:02.913Z
2020-05-05T16:00:03.000Z
Is this normal? Or am I missing something? The reason why my function isn't running because the difference is too big, even when the time set is the same