-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?

6
  • You should use just the numbers, e.g. something like new Date(+date.replace(/\D/g,'')). Commented Jan 5, 2015 at 12:29
  • possible duplicate of Parsing the C# datetime to javascript datetime Commented Jan 5, 2015 at 12:29
  • possible duplicate of ASP.NET MVC JsonResult Date Format Commented Jan 5, 2015 at 12:30
  • 1
    Come on! This question was asked and answered must be hundred times. Use search, you are not novice here. Commented Jan 5, 2015 at 12:34
  • @Fedor—then mark it as a dupe. ;-) Commented Jan 5, 2015 at 12:35

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.