关于JQuery:Javascript日期从毫秒和时区

Javascript Date from milliseconds and timezone

本问题已经有最佳答案,请猛点这里访问。

Possible Duplicate:
How to format a JSON date?
Parsing Date from webservice

抱歉,如果已经问过这个问题。我环顾四周,却找不到一个。有没有一种快速方便的方法,只使用javascriptjQuery将"json"日期转换为人类友好的格式(不包括附加的jQuery库)?

日期格式如下:

1
creationDate:"/Date(1346713200000+0100)/"

谢谢


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
> var maybeDateString ="/Date(1346713200000+0100)/";
> fromDateString(maybeDateString)
Tue Sep 04 2012 02:00:00 GMT+0200

function fromDateString(str) {
    var res = str.match(/\/Date\((\d+)(?:([+-])(\d\d)(\d\d))?\)\//);
    if (res == null)
        return new Date(NaN); // or something that indicates it was not a DateString
    var time = parseInt(res[1], 10);
    if (res[2] && res[3] && res[4]) {
        var dir = res[2] =="+" ? -1 : 1,
            h = parseInt(res[3], 10),
            m = parseInt(res[4], 10);
        time += dir * (h*60+m) * 60000;
    }
    return new Date(time);
}