如何使用 DayJS 在 Javascript 中获取下个月的第一天
有关该库的更多信息,请参阅 dayjs 文档。
first_day_next_month_dayjs.js
const now = dayjs();
const nextMonth = now.month(now.month() + 1).date(1).hour(0).minute(0).second(0);
// 示例用法
console.info(nextMonth.format())
// 打印,例如,"2022-03-01T00:00:00+01:00"
这在 12 月也能工作,因为 DayJS 正确处理 month(13):
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);
// 这打印 '2022-01-01T00:00:00+01:00'
console.info(nextMonth.format());Check out similar posts by category:
Javascript
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow