我希望有人知道我遇到的问题。我对我的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/