I have following code
var res = from c in model.Data
select new object[] { c.Id, c.Time, c.Name };
this res variable is sent as json object.
Time is DateTime property.
I’m fetching this json objects in the view like following
$(document).ready(function () {
$('#myDataTable').dataTable({
"bServerSide": true,
"sAjaxSource": "/Home/AjaxHandler",
"bProcessing": true,
"aoColumns": [
{ "sName": "ID",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj) {
return '<a href=\"Details/' +
oObj.aData[0] + '\">View</a>';
}
},
{ "sName": "Time" },
{ "sName": "Name" }
]
});
});
Page is rendered with datetime fields like /Date(1346996934000)/
What is the best way to convert this, on the server side or in the view and how to do this?
Thanks
Is that number the date in ticks? If that’s the case, then
Found that here: Format from ticks to date
This would be converted to: Fri Sep 07 2012 01:48:54 in GMT-4 timezone.
This is a solution I for doing it in JavaScript, found here: http://deekshadev.blogspot.com/2011/03/convert-ticks-to-date-object.html
If that date is only needed for display, I wouldn’t do it on the server level. I’d convert on the client and display it as needed.