Convert Json date string to JavaScript date object

Posted by dagda1 on Stack Overflow See other posts from Stack Overflow or by dagda1
Published on 2010-06-22T23:52:38Z Indexed on 2010/12/27 15:54 UTC
Read the original article Hit count: 190

Filed under:
|
|

Hi,

I have the following JSON object which has a date field in the following format:

{
    "AlertDate": "\/Date(1277334000000+0100)\/",
    "Progress": 1,
    "ReviewPeriod": 12 
}

I want to write a regular expression or a function to convert it to a javascript object so that it is in the form:

{
    "AlertDate": "AlertDate":new Date(1277334000000),
    "Progress": 1,
    "ReviewPeriod": 12 
}

The above date format fails validation in the JQuery parseJSON method.

I would like to convert the 1277334000000+0100 into the correct number of milliseconds to create the correct date when eval is called after validation.

Can anyone help me out with a good approach to solving this?

Cheers

Paul

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex