Currently, I am utilizing moment 2.16.0
and I am interested in obtaining the starting days of the month. I have noticed that there are varying results when using the toDate()
and format()
methods. To see a demonstration, you can check out this jsfiddle.
Example code snippet:
var time = moment().subtract(0, 'months').startOf("month").format();
console.log(time); //2016-12-01T00:00:00+05:30
var time2 = moment().subtract(0, 'months').endOf("month").format();
console.log(time2); //2016-12-31T23:59:59+05:30
var time = moment().subtract(0, 'months').startOf("month").toISOString();
console.log(time); //2016-11-30T18:30:00.000Z I am looking for a result like 2016-12-01T00:00:00.000Z
var time2 = moment().subtract(0, 'months').endOf("month").toISOString();
console.log(time2); // 2016-12-31T18:29:59.999Z I am expecting a result similar to 2016-12-31T59:59:59.000Z