문제

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top