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}`
        },

 

上一篇:142. 环形链表 II


下一篇:嵌入式基础