How to get first day of next month in Javascript using DayJS
See the dayjs docs for more info about the library.
const now = dayjs();
const nextMonth = now.month(now.month() + 1).date(1).hour(0).minute(0).second(0);
// Example usage
console.info(nextMonth.format())
// Prints, for example, "2022-03-01T00:00:00+01:00"
This will also work in december as DayJS processes month(13)
correctly:
const now = dayjs('2021-12-09');
const nextMonth = now.month(now.month() + 1).date(1).hour(0).minute(0).second(0);
// This prints '2022-01-01T00:00:00+01:00'
console.info(nextMonth.format());