I want to get the date 360 minutes late.
The problem is that when I convert it to a date format with the method, toDate()
it returns the current time without having subtracted the 360 minutes.
// creamos la fecha con 360 minutos antes
const timePast = moment().subtract(360, "minutes").format()
// fecha con 360 minutos menos con tipo string
console.log(timePast)
// imprime la fecha con tipo Date (apararece la hora exacta del momento y no resta los 360 minutos)
console.log(moment(timePast).toDate())
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/moment.min.js"></script>
What I occupy is the date that is
Date
subtracted from the 360 minutes, greetings in advance.
I would do it in 2 steps, first create the date and then use moment to subtract the 360 minutes (6 hours) from the current date, something like this: