gpt4 book ai didi

javascript - 为什么我的 momentjs 对象上缺少 toJSON()?

转载 作者:太空宇宙 更新时间:2023-11-04 03:11:30 25 4
gpt4 key购买 nike

我得到了这种奇怪的效果,就像有时 momentjs 起作用,有时不起作用。

这是版本 1.7.2,在 Node.js 中运行。

reg.date = moment('230420050000','DDMMYYYYHHmm' ).toJSON();

TypeError: Object Sat Apr 23 2005 00:00:00 GMT+0200 (CEST) has no method 'toJSON'

问题 1:这不是实例化 momentjs 对象的正确方法吗?

当我将其转储到控制台时,我看到它具有所有典型的时刻字段:

{ 
_d: {
Fri, 22 Apr 2005 22:00:00 GMT
_a: [ 2005, 3, 23, 0, 0, 0, 0, undefined ]
},
_isUTC: false,
_a: [ 2005, 3, 23, 0, 0, 0, 0, undefined ],
_lang: false
}

问题 2:那么为什么 toJSON() 消失了?

最佳答案

答案1:

根据您的错误

Object Sat Apr 23 2005 00:00:00 GMT+0200 (CEST)

初始化正确。

答案2:

从2.0.0版本开始支持toJson方法:http://momentjs.com/docs/#/displaying/as-json/

关于javascript - 为什么我的 momentjs 对象上缺少 toJSON()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16563643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com