繁体   English   中英

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

[英]How do I format server side Jquery Datatable rendering date from a 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
      }
    ],
  });
});

如果有人可以告诉我如何将呈现的时间戳格式化为更具可读性的格式,我将不胜感激。

您应该查看moment.js来解析时间戳。 也许这个答案会有所帮助, 在JavaScript中将日期从一种格式转换为另一种格式

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM