【问题标题】:Moment.js .toDate() returns one year later than expected resultMoment.js .toDate() 返回比预期结果晚一年
【发布时间】:2020-11-28 09:25:04
【问题描述】:

我有个约会。 2019-12-13 13:40:00 代表 2019 年 12 月 13 日下午 1:40。当我用 moment.js 解析这个时......

moment(props.data[index].date, 'gggg-MM-DD HH:mm:ss')

_d 显示日期为Sun Dec 13 2020 14:30:00 GMT-0800 (Pacific Standard Time)。 我在 GitHub 上看到了很多解释,人们遇到这个问题但它与时区有关,但是一整年的差异不是时区问题。 我该怎么做才能解决这个问题?

【问题讨论】:

    标签: javascript reactjs momentjs


    【解决方案1】:

    第二个参数中的gggg 用于解析ISO week date 格式。 试试moment(props.data[index].date, 'YYYY-MM-DD HH:mm:ss')

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 2016-11-13
      • 1970-01-01
      • 2018-07-31
      • 2021-08-01
      • 1970-01-01
      • 2016-05-07
      相关资源
      最近更新 更多