Ersten Tag des nächsten Monats in JavaScript mit DayJS ermitteln

English Deutsch

Siehe die DayJS-Dokumentation für weitere Informationen zur Bibliothek.

first_day_next_month_dayjs.js
const now = dayjs();
const nextMonth = now.month(now.month() + 1).date(1).hour(0).minute(0).second(0);

// Beispielverwendung
console.info(nextMonth.format())
// Gibt beispielsweise "2022-03-01T00:00:00+01:00" aus

Dies funktioniert auch im Dezember, da DayJS month(13) korrekt verarbeitet:

first_day_next_month_december_dayjs.js
const now = dayjs('2021-12-09');
const nextMonth = now.month(now.month() + 1).date(1).hour(0).minute(0).second(0);

// Dies gibt '2022-01-01T00:00:00+01:00' aus
console.info(nextMonth.format());

Check out similar posts by category: Javascript