Neir0
Neir0

Reputation: 13367

Convert serialized C# DateTime to JS Date object

How can I convert that date format /Date(1302589032000+0400)/ to JS Date object?

Upvotes: 11

Views: 7066

Answers (1)

James Hill
James Hill

Reputation: 61812

Remove the text first:

var src = "/Date(1302589032000+0400)/";

//Remove all non-numeric (except the plus)
src = src.replace(/[^0-9 +]/g, ''); 

//Create date
var myDate = new Date(parseInt(src));

Here's a workding jsFiddle

Upvotes: 19

Related Questions