-1

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?

user441521
  • 6,942
  • 23
  • 88
  • 160
  • [Please please please... show your code](http://stackoverflow.com/help/mcve). – Erik Philips Jul 10 '14 at 17:13
  • Also see http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx – asawyer Jul 10 '14 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. – user441521 Jul 10 '14 at 17:19

1 Answers1

2

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);
Kyle Gobel
  • 5,530
  • 9
  • 45
  • 68