moment js 制作倒计时 比较简单

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script src="https://cdn.bootcdn.net/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
  <script>
    setInterval(() => {
      let start = moment(new Date());//获取开始时间
      let end = moment(new Date("2020/12/20"));//结束时间
      let diff = end.diff(start);//时间差
      let time = `${moment.duration(diff).hours()} - ${moment.duration(diff).minutes()} - ${moment.duration(diff).seconds()}`//格式化为需要的格式 这里是时分秒
      console.log(time)
    }, 1000)
  </script>
</body>

</html>
posted @ 2020-10-27 16:54  阿臻  阅读(3841)  评论(0编辑  收藏  举报