Vue 项目获取当前系统时间解析成年月日周

简单粗暴,直接上代码:

{{ date }}

{{ time }}

data () {

return:{

time: '',

date: '',

week: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],

}

}

mounted () {

setInterval(() => {

this.updateTime()

}, 1000)

this.updateTime()

},

methods: {

updateTime () {

var cd = new Date()

this.time = this.zeroPadding(cd.getHours(), 2) + ':' + this.zeroPadding(cd.getMinutes(), 2) + ':' + this.zeroPadding(cd.getSeconds(), 2)

this.date = this.zeroPadding(cd.getFullYear(), 4) + '-' + this.zeroPadding(cd.getMonth() + 1, 2) + '-' + this.zeroPadding(cd.getDate(), 2) + ' ' + this.week[cd.getDay()]

},

zeroPadding (num, digit) {

var zero = ''

for (var i = 0; i < digit; i++) {

zero += '0'

}

return (zero + num).slice(-digit)

},

handleCurrentChange (val) {

this.currentPage = val

},

}

效果:

Logo

前往低代码交流专区

更多推荐