如何从时间戳格式化服务器端Jquery Datatable呈现日期?

时间:2018-02-18 17:03:19

标签: javascript jquery coldfusion datatables timestamp

我希望有人知道我遇到的问题。我对MySQL数据库进行了ajax调用。我正在使用ColdFusion和jQuery数据表来显示我的字段。一切正常,除非我尝试格式化日期。我曾尝试使用<cfset>格式化JavaScript之前的日期,并尝试了在线发现的其他一些解决方案。以下是我的代码。

$(document).ready(function() {
  var table = $('#TableData').dataTable({
    "bProcessing": true,
    "bStateSave": true,
    "bServerSide": true,
    "sAjaxSource": "MyCFMCall.cfm",
    "aoColumns": [{
        "sName": "ID",
        "sClass": "hidden"
      },
      {
        "sName": "DATABASE_DATE",
        "sTitle": "APP DATE",
        "bSortable": "true"
      } //<!---My timestamp from the database--->

    ],

    "columnDefs": [

      {
        "render": function(data, type, row) {
          return "+row[1]+";
        }, //<!---This will render the timestamp only, yet not formated.--->
        "targets": 1
      }
    ],
  });
});

如果有人能告诉我如何将这个渲染的时间戳格式化为更易读的格式,我真的很感激。

1 个答案:

答案 0 :(得分:1)

你应该查看moment.js来解析时间戳。也许这个答案会有所帮助 Convert Date from one format to another format in JavaScript

另外,如果您能告诉我从服务器接收日期的实际日期格式是什么?并在那里查看第二个答案以避免使用库。