Change date format in js for jquery datatable

瘦欲@ 提交于 2019-12-13 05:11:23

问题


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?


回答1:


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/



来源:https://stackoverflow.com/questions/19276010/change-date-format-in-js-for-jquery-datatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!