es6实现时分秒

获取时分秒的demo呢   有很多    在这里我就简单分享一下我的一个方法  一下代码打印出来的效果格式为      20:28:51

setInterval(()=>{

         constnow =newDate()

         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)}`) // 20:28:51
},1000)

 

posted @ 2018-11-01 15:47  ①丶①۵  阅读(251)  评论(0编辑  收藏  举报