每秒输出格式化的当前时间

setInterval(() => {
      const now = new Date();
      const hours = now.getHours().toString();
      const minutes = now.getMinutes().toString();
      const seconds = now.getSeconds().toString();
      console.log(
        `${hours.padStart(2, 0)}:${minutes.padStart(2, 0)}:${seconds.padStart(
          2,
          0
        )}`
      );
    }, 1000);

 

posted @ 2018-11-02 11:34  陈小银  阅读(223)  评论(0编辑  收藏  举报