I have 2 strings, that have the minute
and hour
that a function needs to occur at.
I want to check, if the minute
and hour
which are specified in string format, and from my database are within 5 minutes of the current time, call this function.
My original thought was something like:
(today.minute is the current minute)
today.minute
:
minute = "55"
hour = "14"
var today = new Date();
var time = today.getMinutes(), today.getHours()
if (today.getMinutes() - 5 == minute) {
myFunc()
}
But that isn't going to work, because I need the hour and minute - 5 minutes... how can I do this?
CodePudding user response:
Is this what you are looking for?
let minute = "55"
let hour = "14"
let today = new Date();
//var time = today.getMinutes(), today.getHours()
if (Math.abs(today.getMinutes() - Number(minute)) <= 5) {
myFunc()
}
function myFunc() {
console.log('myFunc called', today.getMinutes());
}
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>