简体   繁体   中英

Can't Parse JSON Date from SQL Server in Javascript

Im getting a JSON date back from SQL Server that looks like this:

"/Date(-62135568000000-0800)/"

when I try to parse the date using: var date = new Date(parseInt(MyDate) * 1000); I get Invalid Date

ultimately I'm trying to put these dates on an x axis of d3 time series plot.

Is there a way I can use this JSON date value in d3?

EDIT:

I found a work-around on the SQL Server side by returning the number of seconds since 1/1/1970 as an int

You can try this function

function GetJSDateFromMS(str)
{
    return eval("new " + str.replace(/\//g,""));
}

Pass datetim string varibale to function and it will return you a Javascript datetime object.

GetJSDateFromMS("/Date(345345345345)/")

Thu Dec 11 1980 06:45:45 GMT+0530 (India Standard Time)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM