I want to make a method where I generate a list of hours that have already passed in the day, that is, right now it is 10:00 AM, so I want to obtain a list of those that have already passed before 10:00 um, something like this:
- 1:00 AM
- 2:00 A.M
- 3:00AM
- .
- .
- .
- 9:00 AM
I've been doing some research on how I can do it in JS, so far I know it gets now()
you the current time, setHour
updates the time and getHours
gets the current time just like now
const tiempoTranscurrido = Date.now();
const hoy = new Date(tiempoTranscurrido);
hoy.setHours(hoy.getHours() - tiempoTranscurrido)
console.log('tiempoTranscurrido', hoy);
How can I do it? She was thinking of subtracting the hours that have already passed from the current time, does anyone know how? please if someone explain me
If you need to use
Date.now
you can convert the milliseconds to a full date using the constructorDate
, this way we can later usegetHours
and use a loop to count from midnight to the current time to find out how many hours have passed and find out what they are