67,944
社区成员




<!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>Document</title>
</head>
<body>
<script>
//用2022 10 01举例
// 现在到2022 10 01的倒计时
function now() {
// 获取现在到1970年1月1日的总毫秒数
var nowTotalMilliseconds = +new Date() / 1000;
// 2022-10-01获取到1970年1月1日的总毫秒数
var futureTotalMilliseconds = +new Date("2022-10-01 00:00:00") / 1000;
// 取得总毫秒差
var time = futureTotalMilliseconds - nowTotalMilliseconds;
var days = parseInt(time / 60 / 60 / 24);
var hours = parseInt(time / 60 / 60 % 24);
// 补零,看起来美观
hours <= 9 ? "0" + hours : hours;
var minutes = parseInt(time / 60 % 60);
// 补零,看起来美观
minutes <= 9 ? "0" + minutes : minutes;
var seconds = parseInt(time % 60);
// 补零,看起来美观
seconds <= 9 ? "0" + seconds : seconds;
return days + "天" + hours + "小时" + minutes + "分" + seconds + "秒";
}
console.log(now());
</script>
</body>
</html>
学会了