-2

on the aspx I am getting

date = /Date(1420460565000)/

I tried to parse it javascript date bject

var dateformatted = new Date(date);

However when I run it I am getting Invalid Data

How do I parse the c# DateTime object?

user829174
  • 6,132
  • 24
  • 75
  • 125
  • You should use just the numbers, e.g. something like `new Date(+date.replace(/\D/g,''))`. – RobG Jan 05 '15 at 12:29
  • possible duplicate of [Parsing the C# datetime to javascript datetime](http://stackoverflow.com/questions/15829521/parsing-the-c-sharp-datetime-to-javascript-datetime) – Mr Balanikas Jan 05 '15 at 12:29
  • possible duplicate of [ASP.NET MVC JsonResult Date Format](http://stackoverflow.com/questions/726334/asp-net-mvc-jsonresult-date-format) – Fedor Jan 05 '15 at 12:30
  • 1
    Come on! This question was asked and answered must be hundred times. Use search, you are not novice here. – Fedor Jan 05 '15 at 12:34
  • @Fedor—then mark it as a dupe. ;-) – RobG Jan 05 '15 at 12:35
  • @RobG Already done. I just shocked by a fact that user that has been registered for 3 years didn't use Google before asking for such a obviously platinum question. – Fedor Jan 05 '15 at 12:37

1 Answers1

1

You could try this one:

var dateformatted = new Date(parseInt(date.substr(6)));

This works because substr function takes out the "/Date(" part, and the parseInt function gets the integer and ignores the ")/" at the end. The resulting number is passed into the Date constructor. Hence a new Date can be created.

Christos
  • 53,228
  • 8
  • 76
  • 108