ASP. net mvc handles the DateTime problem of JsonResult return time, jsonresultdatetime
When developing ASP. net mvc, if you use jQuery's Ajax to obtain some json data, the data returned contains the date and time, it may be a small problem.
To solve this problem, write a small example to demonstrate how to create a controller in the MVC project:
Write a view:
Let's take a look at this. When you display data in the view without any processing:
Modify the string "/Date (1435542121135)/" to take the digits in the brackets, convert it to int using the parseInt function, and pass it as a parameter of the new date object, in this way, new date is a new time object. :
Code:
Var obj = new Date (parseInt (data. result. substr (6); View Code
Or Replace the redundant characters with Replace:
Code:
Var obj = new Date (parseInt (data. result. replace ("/Date (",""). replace (")/", ""), 10); View Code
In this way, although the date and time information is displayed, it is in UTC format, but it is a bit unfriendly. We need to format it: