<template>
<div>
<div class="headerRightTime">{{nowTimes.yy}}.{{nowTimes.mm}}.{{nowTimes.dd}} {{nowTimes.hou}}:{{nowTimes.min}}</div>
<span>北京市</span>
</div>
</template>
<script>
export default {
data() {
return {
nowTimes: {
yy: "00",
mm: "00",
dd: "00",
hou: "00",
min: "00",
sec: "00"
},
setTime: null
};
},
created() {
setInterval(this.setNowTimes, 1000);
},
mounted() {
this.setTime = setInterval(() => {
this.setNowTimes();
}, 1000);
},
methods: {
setNowTimes() {
let myDate = new Date();
var month = myDate.getMonth() + 1;
this.nowTimes.yy = myDate.getFullYear();
this.nowTimes.mm = String(month < 10 ? "0" + month : month);
this.nowTimes.dd = String(
myDate.getDate() < 10 ? "0" + myDate.getDate() : myDate.getDate()
);
this.nowTimes.hou = String(
myDate.getHours() < 10 ? "0" + myDate.getHours() : myDate.getHours()
);
this.nowTimes.min = String(
myDate.getMinutes() < 10
? "0" + myDate.getMinutes()
: myDate.getMinutes()
);
this.nowTimes.sec = String(
myDate.getSeconds() < 10
? "0" + myDate.getSeconds()
: myDate.getSeconds()
);
}
},
beforeUpdate() {
clearInterval(this.setTime);
}
};
</script>
<style lang="less">
</style>