gpt4 book ai didi

javascript - JS : How to turn this string into date object

转载 作者:行者123 更新时间:2023-11-29 17:24:28 24 4
gpt4 key购买 nike

字符串是

2012-04-13T22:59:33

我试过 Date.parse(str, "Y-m-dTH:i:s") 对我不起作用,我不确定“T”代表什么?

最佳答案

只需将其作为日期的参数:

var date = new Date("2012-04-13T22:59:33");

如果这在旧版浏览器中不起作用,请尝试:

var str = "2012-04-13T22:59:33",
elems = str.split("T"),
date = elems[0].split("-"),
time = elems[1].split(":"),
result = new Date(date[0],date[1]-1,date[2],time[0],time[1],time[2]);

关于javascript - JS : How to turn this string into date object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10142733/

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