js 时间格式化

话不多说  直接上代码

 changeTime(){
            let nowTime = new Date()
            let year = nowTime.getFullYear()
            let month = nowTime.getMonth()+1
            if((month+'').length==1){
                month = '0'+month
            }
            let day = nowTime.getDate()
            let hours = nowTime.getHours()
            if((hours+'').length==1){
                hours = '0'+hours
            }
            let min = nowTime.getMinutes()
            if((min+'').length==1){
                min = '0'+min
            }
            let sec = nowTime.getSeconds()
            return `${year}-${month}-${day}  ${hours}:${min}:${sec}`
        },

 

posted @ 2021-07-29 17:49  ComeIntoBud  阅读(47)  评论(0编辑  收藏  举报