<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
function getTime() {
var now = new Date();
console.log('时间戳',now)
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var ss = now.getSeconds(); //秒
var clock = year + "-";
if (month < 10) {
clock += "0";
}
clock += month + "-";
if (day < 10) {
clock += "0";
}
clock += day + " ";
if (hh < 10) {
clock += "0";
}
clock += hh + ":";
if (mm < 10) {
clock += '0';
}
clock += mm + ":";
if (ss < 10) {
clock += '0';
}
clock += ss;
return (clock);
}
function getDate() {
var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hh = now.getHours(); //时
var mm = now.getMinutes(); //分
var ss = now.getSeconds(); //秒
var clock = year + "-";
if (month < 10)
clock += "0";
clock += month + "-";
if (day < 10)
clock += "0";
clock += day + " ";
// if(hh < 10)
// clock += "0";
//
// clock += hh + ":";
// if(mm < 10) clock += '0';
// clock += mm + ":";
//
// if(ss < 10) clock += '0';
// clock += ss;
return (clock);
}
let time=getTime()
console.log('time',time)
let date=getDate()
console.log('date',date)
</script>
</body>
</html>
js时间戳转xxx-xx-xx格式
最新推荐文章于 2023-04-26 16:52:48 发布