码迷,mamicode.com
首页 > 其他好文 > 详细

vue获取当下日期时间及周几

时间:2019-11-14 17:57:29      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:gets   set   ted   ons   span   time   minutes   mes   interval   


星期四     2019-11-14     17:27:09

HTML

<span>{{nowWeek}}</span> &nbsp; &nbsp;
<span>{{nowDate}}</span> &nbsp; &nbsp;
<span>{{nowTime}}</span>

data

data () {
return {
timer: null,
nowWeek: ‘‘,
nowDate: ‘‘,
nowTime: ‘‘
}
}

mounted

mounted () {
this.timer = setInterval(() => {
this.setNowTimes()
}, 1000)
}

methods

setNowTimes () {
let myDate = new Date()
// console.log(myDate)
let wk = myDate.getDay()
let yy = String(myDate.getFullYear())
let mm = myDate.getMonth() + 1
let dd = String(myDate.getDate() < 10 ? ‘0‘ + myDate.getDate() : myDate.getDate())
let hou = String(myDate.getHours() < 10 ? ‘0‘ + myDate.getHours() : myDate.getHours())
let min = String(myDate.getMinutes() < 10 ? ‘0‘ + myDate.getMinutes() : myDate.getMinutes())
let sec = String(myDate.getSeconds() < 10 ? ‘0‘ + myDate.getSeconds() : myDate.getSeconds())
let weeks = [‘星期日‘, ‘星期一‘, ‘星期二‘, ‘星期三‘, ‘星期四‘, ‘星期五‘, ‘星期六‘]
let week = weeks[wk]
this.nowDate = yy + ‘-‘ + mm + ‘-‘ + dd
this.nowTime = hou + ‘:‘ + min + ‘:‘ + sec
this.nowWeek = week
}

 

vue获取当下日期时间及周几

标签:gets   set   ted   ons   span   time   minutes   mes   interval   

原文地址:https://www.cnblogs.com/luckyShuang/p/11858823.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!