0

i am getting stucked to convert date from ms (receiving from json) i was recieving the date in json in format below

/Date(1355250600000)/

so that i converted it into ms --->

var d = response.ContributionsDate.replace("/", "").replace("/", "").replace("Date(", "").replace(")", "");

so now its d = 1355250600000

to convert i tried the code below--->

            var date = new Date(d);
            alert(date);

but did not work (invalid date), if anyone have any idea about date parsing, help me

Ashok Damani
  • 3,896
  • 4
  • 30
  • 48

1 Answers1

5

d is a string, not a number.

Try

var date = new Date(+d);

instead.

The prefix + causes coercion to a number.

Incidentally, you can simplify your replace operations to

var d = +response.ContributionsDate.match(/^\/Date\((\d+)\)\/$/)[0];
Mike Samuel
  • 118,113
  • 30
  • 216
  • 245