Javascript Date from milliseconds and timezone

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

Sorry if this question has already been asked. I have look around but have been unable to find one. Is there a quick and convenient way to convert a "json" date into a human friendly format using only javascript and jQuery (excluding additional jQuery libraries)?

The date is format is the following:

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

Thanks


> 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+)(?:([+-])(dd)(dd))?)//);
    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);
}
链接地址: http://www.djcxy.com/p/8158.html

上一篇: Javascript将日期转换为UTC

下一篇: Javascript从毫秒和时区开始的日期