// 时间格式化函数
            function timeFormat() {
                var time = new Date()
                var year = time.getFullYear()
                var month = time.getMonth() + 1 < 10 ? '0' + (time.getMonth() + 1) : time.getMonth() + 1;
                var day = time.getDate() < 10 ? '0' + time.getDate() : time.getDate()
                var hour = time.getHours() < 10 ? '0' + time.getHours() : time.getHours()
                var minute = time.getMinutes() <10 ? '0'+ time.getMinutes() : time.getMinutes()
                var second = time.getSeconds() <10 ? '0'+ time.getSeconds() : time.getSeconds()
                let currentTime = `${year} 年 ${month} 月 ${day} 日 ${hour} 时 ${minute} 分 ${second} 秒`
                return currentTime
            }
setInterval(function () {
      //定时器,一秒钟执行一次 console.log(timeFormat()) },
1000)

 

posted on 2020-09-14 10:05  菜鸟成长日记lx  阅读(431)  评论(0编辑  收藏  举报