dayjs('2018/2/28').add(1,'month').format('YYYY/MM/DD') => 2018/3/28
but i want 2018/3/31
dayjs('2018/4/30').add(1,'month').format('YYYY/MM/DD') => 2018/5/30
but i want 2018/5/31
Is that a bug ?
The add method adds a calendar month. Not 30 or 31 days to move the date always to the end of the month. The method add cannot know, which one of the two options you want :-) If you want the end of the month, have a look at endOf:
dayjs('2018/2/28').add(1,'month').endOf('month')
dayjs('2018/4/30').add(1,'month').endOf('month')
Most helpful comment
The
addmethod adds a calendar month. Not 30 or 31 days to move the date always to the end of the month. The methodaddcannot know, which one of the two options you want :-) If you want the end of the month, have a look atendOf: