日期对象
1、日期对象的概念
Date
对象是 JavaScript 原生的时间库。它以国际标准时间(UTC)1970年1月1日00:00:00作为时间的零点,可以表示的时间范围是前后各1亿天(单位为毫秒)。Date对象保存的日期能够精确到1970年1月1日之前或之后的285616年。1m = 1ms
一天:24 * 60 * 60 * 1000 毫秒数
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>时钟</title>
<style>
.box {
width: 500px;
height: 200px;
background-color: #eee;
margin: 40px auto 0;
text-align: center;
}
#p1 {
margin-top: 50px;
font-size: 40px;
font-width: 700;
}
</style>
</head>
<body>
<div class="box">
<p>在页面显示一个时钟</p>
<p id="p1"></p>
</div>
<script>
//获取p1标签
var pObj = document.getElementById('p1');
//设置定时器
setInterval(function () {
var dt = new Date();
pObj.innerText = dt.toLocaleString();
}, 1000);
</script>
</body>
</html>
二、日期对象创建
日期对象的创建方式
创建一个新Da