gpt4 book ai didi

javascript - 弃用警告 : moment construction falls back to js Date in nodejs

转载 作者:搜寻专家 更新时间:2023-11-01 00:40:14 26 4
gpt4 key购买 nike

我在 nodejs 服务器中使用以下代码使用 moment 将字符串格式化为 ISO8601 标准

var dateStr = "2016-5-20 17:25:45";
var urecordtime=moment(dateStr).toISOString();

但是我得到了

"Deprecation warning: moment construction falls back to js Date. This is discouraged and will be removed in upcoming major release. Please refer to https://github.com/moment/moment/issues/1407 for more info."

我该如何解决?

提前致谢。

最佳答案

尝试将格式指定为第二个参数,这样库就不需要猜测实际格式:

var m = moment("2016-5-20 17:25:45", "YYYY-M-D HH:mm:ss");
var s = m.toISOString();

来源:

http://momentjs.com/docs/#/parsing/
https://github.com/moment/moment/issues/1407

关于javascript - 弃用警告 : moment construction falls back to js Date in nodejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37343173/

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