我希望有人能解决我遇到的问题。我对 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 来解析时间戳。也许这个答案会有一些帮助 Convert Date from one format to another format in JavaScript
另外,如果您能告诉我当您从服务器收到日期时实际的格式是什么?并查看第二个答案以避免使用库。
关于javascript - 如何根据时间戳格式化服务器端 Jquery Datatable 呈现日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48854284/