0

I have this date in table: "2013-10-08T00:00:00" I want to set it in format "dd.MM.yyyy"

in datatable source i changed like this:

{
     "bSortable": true,
     "mData": "PublishDate",
     "bSearchable": true,
     "mRender": function (data, type, row) {
                             if (data) {
                                 debugger;
                                 var re = /-?\d+/;
                                 var m = re.exec(data);
                                 var d = new Date(parseInt(m[0]));
                                 var curr_date = d.getDate();
             var curr_month = d.getMonth() + 1; //Months are zero based
              var curr_year = d.getFullYear();
  var formatedDate = curr_date + "/" + curr_month + "/" + curr_year + " " + d.getHours() + ":" + d.getMinutes();
                                 return formatedDate;
                             }
                             else
                                 return data
                         },
                     },

But it always return 1/1/1970 2:0

have any suggestions?

Alex
  • 8,908
  • 28
  • 103
  • 157

1 Answers1

4

Try this:

var m = data.split(/[T-]/);
var d = new Date(parseInt(m[0]),parseInt(m[1])-1,parseInt(m[2]));

See: http://jsfiddle.net/vHTWL/

Bumptious Q Bangwhistle
  • 4,689
  • 2
  • 34
  • 43