关于日期对象理解
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>倒计时效果</title>
</head>
<body>
<script>
function coutDown(time) {
var nowTime = +new Date(); // 返回的是当前时间总的毫秒数
var inputtime = +new Date(time); // 返回的是用户输入时间总的毫秒数
var times = (inputtime - nowTime) / 1000; // times是剩余时间的总数
var d = parseInt(times / 60 / 60 / 24);
d = d > 10 ? d : '0' + d;
var h = parseInt(times / 60 / 60 % 24);
h = h > 10 ? h : '0'+ h;
var m = parseInt(times / 60 % 60);
m = m > 10 ? m : '0' + m;
var s = parseInt(times % 60);
s = s > 10 ? s : '0' + s;
return d + '天' + h + '时' + m + '分' + s + '秒';
}
console.log(coutDown('2021-10-5 22:00:00'));
var date = new Date();
console.log(date);
</script>
</body>
</html>
这是我学习的一些笔记,把代码放在编译器运行,或者里面有详细的注解希望有帮助!