Datatable displays Date in this format /Date(1103729592973)/.

Datatable displays Date in this format /Date(1103729592973)/.

sureshrajamanisureshrajamani Posts: 1Questions: 0Answers: 0
edited February 2013 in DataTables 1.9
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.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited February 2013
    Your post in the 'How are you using DataTables' thread was utterly inappropriate. Please do not do that again.

    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
  • BLSullyBLSully Posts: 24Questions: 1Answers: 0
    This is more a .NET issue.... .NET serializes DateTime types to that format. You need to do some intermediate processing to your data (specifically, converting that string to a JavaScript Date object) before you feed it to DataTables for display.

    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]
  • d2020d2020 Posts: 3Questions: 0Answers: 0
    Where would I put this function if specifying the json text file in my parameters for DataTable?
  • d2020d2020 Posts: 3Questions: 0Answers: 0
    edited May 2013
    My solution:

    "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..
  • d2020d2020 Posts: 3Questions: 0Answers: 0
    If there are any corrections, improvements, or better ways to do this I'd love to hear about it.
    Thanks...
This discussion has been closed.