因此,我目前正在创建一个使用Oracle数据库中的数据的网页。我正在从数据库中检索数据列表,并在网页上显示它。问题是,当检索数据时,列表中的日期返回为JSON日期。
因此,每当我使用JSON从数据库中检索一个日期并试图在我的网页上显示它时,它的格式如下:"/Date(1404860400000)/“
我怎样才能把这个转变成“dd-mm”这样的日期:“21-8月14日”?
我目前的代码如下:
JavaScript -用于格式化数据并在HTML中显示
var AuditHTML = "<table class='tablesorter full_width_table info_table_style ui-body-d ui-shadow table-stripe ui-responsive' id='auditTable'>" +
"<thead >" +
"<tr class='ui-bar-b schedule_row '>" +
"<th>ID</th>" +
"<th>User ID</th>" +
"<th>Action</th>" +
"<th>Date</th>" +
"<th>App ID</th>" +
"<th>Device ID</th>" +
"<th>Notes</th>" +
"</tr>" +
"</thead>" +
"<tbody>";
for (s = 0; s < auditList.length; s++) {
if (auditList[s].Date <= loggingto && auditList[s].Date >= loggingfrom) {
AuditHTML += "<tr class='schedule_row display' id='auditTr_" + s + "'>" +
"<td> " + auditList[s].ID + "</td>" +
"<td> " + auditList[s].UserID + "</td>" +
"<td> " + auditList[s].Action + "</td>" +
"<td> " + auditList[s].Date + "</td>" +
"<td> " + auditList[s].AppID + "</td>" +
"<td> " + auditList[s].DeviceID + "</td>" +
"<td class='note'> " + auditList[s].Notes + "</td>";
AuditHTML += "</tr>";
}
}
AuditHTML += "</tbody></table>";
$("#auditContent").html(AuditHTML);HTML -显示表
<div id="auditContent">
</div>谢谢你的时间/帮助!
发布于 2014-08-21 14:51:00
我自己用JQuery矩解决了这个问题:
创建一个方法来运行每个JSON日期:
function parseJsonDate(jsonDateString) {
return moment(jsonDateString).format("D-MMM-YY").toUpperCase();
}并在呈现表时调用它:
"<td> " + parseJsonDate(auditList[s].Date) + "</td>" +发布于 2014-08-21 13:07:33
查看JavaScript date对象。您可以将日期以毫秒为单位传递到其构造函数中。
var d = new Date(1404860400000);然后,您可以调用各种get方法以返回所需格式的日期。
date.asp
https://stackoverflow.com/questions/25426952
复制相似问题