سؤال

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