gpt4 book ai didi

javascript - 将日期从一种给定格式转换为另一种给定格式

转载 作者:行者123 更新时间:2023-12-03 01:06:31 25 4
gpt4 key购买 nike

我有这种格式的日期,

Tue Sep 04 2018 05:30:00 GMT 0530 (India Standard Time).

我需要将其转换为这种格式

2018-12-16T00:00:00.000Z

如果我将第一个存储在变量中并尝试 x.toISOString(),它会抛出错误。

完成此任务的正确方法应该是什么?

最佳答案

function myFunction() {
var d = new Date();
var n = d.toISOString();
document.getElementById("date").innerHTML = n;
}
<button onclick="myFunction()"> Date in ISO</button>

<div id="date"></div>

关于javascript - 将日期从一种给定格式转换为另一种给定格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52381530/

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