-1
I would like to make a code that takes time and minute so that I can work with a schedule for the execution of an action, example:
var inserirProgramAtual = document.getElementById("CBNestudio");
if ((new Date().getDay() > 0) && (new Date().getDay() < 6)) {
if (new Date().getHours() >= 5 && new Date().getHours() <= 9) {
inserirProgramAtual.innerHTML = `
<span>Jornal da manhã</span>
`
} else if (new Date().getHours() >= 9 && (new Date().getHours() <= 10)) {
inserirProgramAtual.innerHTML = `
<span>Programa qualquer</span>
`
I managed to pick up the schedule normally, which is 9 o'clock, but what could I do to get 30 minutes? For example, I want at 9:10 or 9:30 to perform an action.
Please explain more clearly your question.
– Wictor Chaves
It’s not just calling
getMinutes
? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getMinutes– hkotsubo
I want the code action to run at 9:30 am, I’ve tried with getMinutes and it didn’t work
– Rafael Oliveira
In this case, I agree with Wictor that it is not clear what you want and how you are doing it. Please click [Edit] and explain in more detail what you want to do and what do you mean "it didn’t work" (gave some error? the code behaved unexpectedly? what? etc). In other words, try to make a [mcve]
– hkotsubo
I edited, in case it still doesn’t help I try to be clearer, sorry the question misspelled.
– Rafael Oliveira
Are you thinking the information from where? And what do you want to do with this information?
– Wictor Chaves
The focus is the code line: if (new Date().getHours() >= 5 && new Date().getHours() <= 9) {...} .
– Rafael Oliveira
Okay, so the script would be triggered at exactly 9:30. Who would keep an eye on the clock and finger on the mouse button to run the script at the exact moment the time is 9:30? Easier to make parole if the current time and minute is greater than 9:30 am
– user60252