0

我的日期以这种格式显示在数据表中:“2013-09-02 12:00:00 AM”

我想要这种格式:"2013/09/02"

我用谷歌搜索并找到了一种方法。但是代码不起作用。输出显示“NaN/NaN/NaN”。

我的数据表脚本在这里:

$(document).ready(function () {
    $('#RequisitionTbl').dataTable({
        "aoColumnDefs": [
            {
                "aTargets": [0],
                "sType": 'date',
                "fnRender": function (oObj) {      // trying to format(like "2013/09/02") the date here

                    var javascriptDate = new Date(oObj.aData[0]);
                    javascriptDate = javascriptDate.getDate() + "/" + javascriptDate.getMonth() + "/" + javascriptDate.getFullYear();
                    return "<div class= date>" + javascriptDate + "<div>";
                }
            },

            { "sWidth": "350px", "aTargets": [0] },
            { "sWidth": "180px", "aTargets": [1] },
            { "sWidth": "200px", "aTargets": [2] },
            { "bSortable": false, "aTargets": [4] },
            { "bSearchable": false, "aTargets": [4] }
        ],
        "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
        "sPaginationType": "bootstrap",
        "oLanguage": {
            "sLengthMenu": "Display _MENU_ records"
        }
    }).columnFilter({
        sPlaceHolder: "head:before",
        aoColumns: [
                        { type: 'date-range' }, ,{},]
    });
});

需要帮助找出问题。

4

1 回答 1

1

请记住,这Month是从零开始的索引:

var currentDate = new Date();
var day = currentDate.getDate();
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();

var javascriptDate = year + '/' + month + '/' + day // Modify as you need

希望这可以帮助!

于 2013-09-25T16:32:53.180 回答