Datatable displays Date in this format /Date(1103729592973)/.
Datatable displays Date in this format /Date(1103729592973)/.
sureshrajamani
Posts: 1Questions: 0Answers: 0
I am using asp.net MVC.I am send JSON Result (which contains generic List of Object) to jquery datatable.My object contains a DateTime type Property.It displays the Date column in this format /Date(1103729592973)/.How to fix this.Can anyone please help.
This discussion has been closed.
Replies
Please also follow the forum rules and post a test case: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read
This is what I use:
[code]
function convertNETDateTime(sNetDate) {
if (sNetDate == null) return null;
if (sNetDate instanceof Date) return sNetDate;
var r = /\/Date\(([0-9]+)\)\//i
var matches = sNetDate.match(r);
if (matches.length == 2) {
return new Date(parseInt(matches[1]));
}
else {
return sNetDate;
}
}
[/code]
"aoColumns":[....
...
{"mData": 12, "mRender": function (data, type, full) { return dtConvFromJSON(data); } }, //"entry_date"}
....
] } );
(pieced together from various date manipulation posts)
function dtConvFromJSON(data)
{
if (data == null) return '1/1/1950';
var r = /\/Date\(([0-9]+)\)\//gi
var matches = data.match(r);
if (matches == null) return '1/1/1950';
var result = matches.toString().substring(6,19);
var epochMilliseconds = result.replace(
/^\/Date\(([0-9]+)([+-][0-9]{4})?\)\/$/,
'$1');
var b = new Date(parseInt(epochMilliseconds));
var c = new Date(b.toString());
var curr_date = c.getDate();
var curr_month = c.getMonth() + 1;
var curr_year = c.getFullYear();
var curr_h = c.getHours();
var curr_m = c.getMinutes();
var curr_s = c.getSeconds();
var curr_offset = c.getTimezoneOffset()/60
var d = curr_month.toString() + '/' + curr_date + '/' + curr_year + " " + curr_h + ':' + curr_m + ':' + curr_s;
return d;
}
..end..
Thanks...