0

我在表中有这个日期:“2013-10-08T00:00:00”我想将其设置为“dd.MM.yyyy”格式

在数据表源中我改变了这样的:

{
     "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
                         },
                     },

但它总是返回 1/1/1970 2:0

有什么建议吗?

4

1 回答 1

4

尝试这个:

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

见:http: //jsfiddle.net/vHTWL/

于 2013-10-09T17:26:16.797 回答