원본 js 시간 스탬프 변환
11149 단어 프런트엔드
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> </title>
</head>
<body>
<div id="time">1571885816</div>
<div id="times">1571885818</div>
<script>
window.onload=function () {
getDate();
}
var time=document.getElementById("time");
console.log(time);
var times=document.getElementById("times");
function getDate(){
toDate(time.innerHTML);
time.innerHTML=str;
toDate(times.innerHTML);
times.innerHTML=str;
}
var str=""
function toDate(number) {
alert(2);
console.log(number);
// ,
var n = number * 1000;
var date = new Date(n);
var Y = date.getFullYear() + '-';
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
var h = date.getHours() + ':';
var m = date.getMinutes() + ':';
var s = date.getSeconds();
console.log((Y + M + D + " " + h + m + s));
return str=(Y + M + D + " " + h + m + s);
}
</script>
</body>
</html>