<!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>
<script>
//格式化日期 时分秒
var time = new Date();
console.log(date.getHours());
console.log(date.getMinutes());
console.log(date.getSeconds());
function getTimer() {
var time = new Date();
var y = date.getFullYear();
var m = date.getMonth() + 1;
var d = date.getDate();
var w = date.getDay();
var w1 = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
var h = date.getHours();
h = h < 10 ? '0' + h : h;
var min = date.getMinutes();
min = min < 10 ? '0' + min : min;
var s = date.getSeconds();
s = s < 10 ? '0' + s : s;
return '现在是:' + y + '年' + m + '月' + d + '日' + h + ':' + min + ':' + s + ' ' + w1[w];
}
console.log(getTimer());
</script>
</head>
<body>
</body>
</html>