我用javascript编写代码
if(issuehistory.length)
{
for (var k in issuehistory) {
$('.library_info_tbl_books tbody').prepend('<tr>' +
...
...
'<td class="text-center centeralign"> ' + issuehistory[k]['due_date'] + '</td>' +
'</tr>');
console.log(issuehistory[k]['due_date']);
}
}
控制台中截止日期的输出显示为
Object
sec: 1510959600
usec: 0
__proto__
:
Obj
...
Object
sec: 1510959600
usec: 0
__proto__
:
Obj
在浏览器内部表格中,它呈现为“[object Object]”
请帮助我如何将其转换为mm / dd / yyyy格式?
答案 0 :(得分:3)
您无法显示对象,因此您必须先获取sec
的值。
试试
if (issuehistory.length) {
for (var k in issuehistory) {
$('.library_info_tbl_books tbody').prepend('<tr>' +
...
...
'<td class="text-center centeralign"> ' + (new Date(issuehistory[k]['due_date']['sec'] * 1000).toLocaleDateString()) + '</td>' +
'</tr>');
console.log(issuehistory[k]['due_date']);
}
}