2

字符串是

2012-04-13T22:59:33

我试过Date.parse(str, "Y-m-dTH:i:s")哪个不适合我,我不确定那个“T”代表什么?

4

1 回答 1

5

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

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]);
于 2012-04-13T14:30:24.043 回答