I know that the month starts counting from scratch, that's why one more month comes out and I have to take one from him. But because the day shows one less?
var fecha = new Date(1989, 10, 10);
//1989-11-09T23:00:00.000Z
I know that the month starts counting from scratch, that's why one more month comes out and I have to take one from him. But because the day shows one less?
var fecha = new Date(1989, 10, 10);
//1989-11-09T23:00:00.000Z
Depends on your time zone. When creating the date you are creating a date on November 10, 1989 at 00:00 in your time zone.
What you are showing is the same date in ISO format that shows the date regarding UTC time use.
The date for your time zone is still correct in any case:
var fecha = new Date(1989, 10, 10);
console.log('Formato ISO:', fecha.toISOString());
console.log('Formato local:', fecha.toLocaleString());
The problem is with the UTC time difference compared to GMT. To calculate it with your local time you can create the date
var fecha = new Date(1989, 10, 10);
var fecha= new Date(fecha.valueOf() + fecha.getTimezoneOffset() * 60000);
This way if the Fri will be released Nov 10 1989 00:00:00 GMT 0000
The 00:00:00 will be the time difference you have according to your time use. That is to say that according to your time use you will leave in hours minutes and seconds instead of 00:00:00 if your time use is -05: 00 then it will come out:
Fri Nov 10 1989 05:00:00 GMT -0500
Because simply the constructor Date
receives the parameters:
new Date(
año_num,
mes_num,
dia_num
)
Done, year_num, month_num, dia_num are integer values with representations of the parts of a date. As a whole value, the month is represented as 0 to 11, with 0 = January and 11 = December.
Reference: