|
<script type="text/javascript">
$(function () {
$("#Grid").ejGrid({
dataSource: ej.parseJSON(Data),
allowFiltering:true,
filterSettings:{filterType:"Excel"},
allowPaging: true,
columns: [
{ field: "OrderDate", format: "{0:MM/dd/yyyy hh:mm:ss}",headerText: 'Due Date', width: 80 },
]
});
});
</script> |
JSON does not know anything about dates. What .NET does is a non-standard hack/extension. The problem with dates in JSON and really JavaScript in general – is that there's no equivalent literal representation for dates. In JavaScript following Date constructor straight away converts the milliseconds since 1970 to Date as follows:
var jsonDate = new Date(1297246301973);
Then let's convert it to js format:
var date = new Date(parseInt(jsonDate.substr(6)));
The substr() function takes out the /Date( part, and the parseInt() function gets the integer and ignores the )/ at the end. The resulting number is passed into the Date constructor .