How to serialize a datetime displaying in the dd-MM-yyyy hh:mm:ss format

Asked

Viewed 275 times

3

How do I send to View() of my Controller in Json format, the default formatted date dd-MM-yyyy hh:mm:ss?

In the transport of data between View and Controller I am using AJAX.

public ActionResult GetList(Object abc) {

...

ObjEntity temp = methodGetInDB();

 string valueJson =  new JavaScriptSerializer().Serialize(temp);

//Saída temp: "Date":"\/Date(1483290061000)\/"

}

1 answer

1

One output would be to convert Datetime to formatted string and then return it to view as json.

Ex: DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss");

  • there are other ways like in the post: http://stackoverflow.com/questions/18635599/specifying-a-custom-datetime-format-when-serializing-with-json-net

  • Thanks for the indication, it worked great here !!! =)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.