我有一個jQuery表格,其中包含以毫秒爲單位的日期格式的列。我想從毫秒轉換爲mm/dd/yyyy。我一直無法弄清楚如何轉換日期值並將其整合到我的腳本中。以毫秒爲單位的日期轉換爲dd/mm/yyyy
請看看我的小提琴和提供任何意見,你可能有:http://jsfiddle.net/tommy6s/eLbq2wvh/
$(document).ready(function() {
$.getJSON("http://www.corsproxy.com/dvl.thomascooper.com/data/json_return.json", function(data) {
//static table head
$('table.stats').append("<th>" + "</th>" + "<th>" + "Date" + "</th>" + "<th>" + "Brand" + "</th>" + "<th>" + "Author" + "</th>" + "<th>" + "Title" + "</th>" + "<th>" + "Posts" + "</th>" + "<th>" + "Exposure" + "</th>" + "<th>" + "Engagement" + "</th>");
//loop through json data
$.each(data.data.rows, function(i, val) {
//+1 to number each row starting at 1
var rowNum = i + 1;
//create table rows and cell and populate with data
$('table.stats').append("<tr>" + "<td>" + rowNum + "</td>" + "<td>" + val[0].value + "</td>" + "<td>" + val[1].value + "</td>" + "<td>" + val[2] + "</td>" + "<td>" + val[3].label + "</td>" + "<td>" + val[4].values[0] + "</td>" + "<td>" + val[5].values[0] + "</td>" + "<td>" + val[6].values[0] + "</td>" + "</tr>");
});
});
});
http://jsfiddle.net/tommy6s/eLbq2wvh/ – t6s 2014-11-23 07:03:52
您可以使用:var date = new Date(val in msec);在這裏解釋:http://stackoverflow.com/questions/8579861/how-to-convert-milliseconds-into-a-readable-date – 2014-11-23 07:12:14
謝謝你的建議亞歷克斯。 – t6s 2014-11-23 08:11:00