我正在使用通过 RequireJS 包含的 Moment.js。当我打电话给
Moment().month()
时,我总是得到 10 号而不是 11 号。知道怎么会发生这种情况吗?
moment().month 获取或设置月份并接受从 0 到 11 的数字。这里的关键是索引从 0 开始,而不是 1。下面的代码将作为这个问题的解决方案。
{Moment(yourDate).month(Moment(yourDate).month()-1).format("MMMM Do YYYY")}
8/30/2022 以上代码将显示 2022 年 8 月 30 日。
{Moment(yourDate).month(Moment(yourDate).month()-1).format("MM-DD-YYYY")}
8/30/2022 以上代码将显示 08-30-2022.
{Moment(yourDate).format("MM-DD-YYYY")}
8/30/2022 以上代码将显示 09-30-2022.