<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>时间戳转换为时间</title>
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
</head>
<body>
<div id="rightalarm">
</div>
</body>
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$.ajax({
url: "data.json", //json文件位置
type: "GET", //请求方式为get
dataType: "json", //返回数据格式为json
success: function(data) { //请求成功完成后要执行的方法
$.each(data, function(i, item) {
var html = "";
var date = new Date(item.visitTime);
//date.setTime(inTime);
var month = date.getMonth() + 1;
var days = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
var second = date.getSeconds();
if (month < 10) {
month = '0' + month;
}
if (days < 10) {
days = '0' + days;
}
if (hours < 10)
hours = "0" + hours;
if (minutes < 10)
minutes = "0" + minutes;
if (second < 10)
second = "0" + second;
var time = date.getFullYear() + "-" + month + "-" + days +" " + hours + ":" + minutes +":"+second;
html += ' <div >' +time + ' </div>';
$("#rightalarm").append(html);
})
}
})
})
</script>
</html>
json
[
{
"visitTime": 1628844371414
}, {
"visitTime": 1572512489920
}, {
"visitTime": 1572512489920
}, {
"visitTime": 1572512489920
}, {
"visitTime": 1572512489920
}, {
"visitTime": 1572513935374
}
]
|