Вопрос

I used subtract function to get Nature month, but it's not work. following is my code

var month = moment('2013-12-31').subtract('month',1);     

I want result is 2013-12-01 but it response 2013-11-30.

I don't know what wrong with it?

Anyone can help me?

Thanks!

Это было полезно?

Решение

you are subtracting the month from the date and expecting the result from the same month. it seems like moment is working fine. if you want that result add one more day to the response.

try this

var month = moment('2013-12-31').subtract('month',1).add('days',1);

This will subtract one month from the data and add one day to so you will get the correct response. that is first of that month.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top