gpt4 book ai didi

javascript - 如何将此日期 'Wed Mar 9 09:48:09 PST 2016'转换为 'YYYY-MM-DD HH:mm:ss'格式?

转载 作者:行者123 更新时间:2023-11-28 18:42:37 26 4
gpt4 key购买 nike

我正在尝试从此格式转换日期时间值 Wed Mar 9 09:48:09 PST 2016转换为以下格式 YYYY-MM-DD HH:mm:ss

我尝试使用 moment但它给了我一个警告。

"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.
Arguments: [object Object]
fa/<@http://localhost:1820/Resources/Scripts/Plugins/moment.min.js:7:9493
ia@http://localhost:1820/Resources/Scripts/Plugins/moment.min.js:7:10363
Ca@http://localhost:1820/Resources/Scripts/Plugins/moment.min.js:7:15185
Ba@http://localhost:1820/Resources/Scripts/Plugins/moment.min.js:7:15024
Aa@http://localhost:1820/Resources/Scripts/Plugins/moment.min.js:7:14677
Da@http://localhost:1820/Resources/Scripts/Plugins/moment.min.js:7:15569
Ea@http://localhost:1820/Resources/Scripts/Plugins/moment.min.js:7:15610
a@http://localhost:1820/Resources/Scripts/Plugins/moment.min.js:7:41
@http://localhost:1820/Home/Test:89:29
jQuery.event.dispatch@http://localhost:1820/Resources/Scripts/Jquery/jquery.min.js:5225:16
jQuery.event.add/elemData.handle@http://localhost:1820/Resources/Scripts/Jquery/jquery.min.js:4878:6
"

根据https://github.com/moment/moment/issues/1407我不应该尝试使用 moment() 来执行此操作,因为它不可靠。

如何可靠地转换 Wed Mar 9 09:48:09 PST 2016转换为以下格式 YYYY-MM-DD HH:mm:ss

最佳答案

您可以尝试使用Date.toJSON() , String.prototype.replace() , <罢工> trim()

var date = new Date("Wed Mar 9 09:48:09 PST 2016").toJSON()
.replace(/(T)|(\..+$)/g, function(match, p1, p2) {
return match === p1 ? " " : ""
});

console.log(date);

关于javascript - 如何将此日期 'Wed Mar 9 09:48:09 PST 2016'转换为 'YYYY-MM-DD HH:mm:ss'格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35899498/

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