Faced such a problem: I want to take the date of the previous day, but when the date is the first day of the year, then the javascript date does not work correctly.
Here is a sample code:
Here I have to return such result day - 31, month - 11 (месяцы из даты начинаются с 0 до 11) и year - 2016 , but my result in the example is such a day - 31, month - 0, year - 217
var d = new Date(2017, 1, 1); d = new Date(d.getTime() - 86400000); var from_day = d.getDate(); console.log(d.getTime()); console.log(from_day); console.log(d.getMonth()); console.log(d.getFullYear());