0

I have an MVC action that returns JsonResult which I pass in a class where one field is a DateTime field. When I read that field in from javascript it's display like:

/Date(1391666400000)/

public JsonResult GetDate()
{
   return Json(DateTime.Now(), JsonRequestBehavior.AllowGet);
}

How can I convert this to just say "2/6/2014" like it was when coming from .NET?

3
  • Please please please... show your code. Commented Jul 10, 2014 at 17:13
  • Also see hanselman.com/blog/… Commented Jul 10, 2014 at 17:14
  • Erik this is such a small example I figured an explanation of what I was looking to do was enough, but I showed the simple example code above now. Commented Jul 10, 2014 at 17:19

1 Answer 1

3

The comments link better answers and explanations, but personally I just use a quick dirty javascript function like so

function date(s) { 
  return new Date(parseFloat(/Date\(([^)]+)\)/.exec(s)[1])); 
}

var jsDate = date(jsonDateFromDotNet);
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect thanks. Simple and to the point. I like answers like that!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.