Very simple question.
I am working on a angularjs app retrieving data from an asp.net web api. I have a date field (ThisDate) in a table (Model) which has date format like this -
2015-03-14 12:39:32.470
When I send this as a response json string from asp.net -
string json = "{\"CreatedAt\": \"" + Model.ThisDate + "\"}";
response.Content = new StringContent(json, Encoding.UTF8, "application/json")
..I am getting it like this in angularjs app -
14-03-2015 12:39:32
And When I send it as a json serialized object from asp.net -
JsonConvert.SerializeObject(Model)
..I am getting it like this in angularjs app -
2015-03-14T12:39:32.470
What are the reasons for this to be different? I want both to be in second format, so sorting works correctly. How to achieve this?
Thanks in advance.
I am still not sure why it converts they way it does. But I was able to fix this by specifying a sortable datetime format while sending response json string as below -
string json = "{\"CreatedAt\": \"" + Model.ThisDate.ToString("s") + "\"}";
Refer here