<template>
<view>
<view class="box">
{{inYear}}
</view>
<view class="box">
{{inDay}}
</view>
<view class="box">
{{inTime}}
</view>
</view>
</template>
<script>
export default {
data() {
return {
// 日期
inYear: '',
// 星期
inDay: '',
inTime: '',
};
},
onShow() {
setInterval(() => {
let times = new Date()
// 日期
let years = times.getFullYear()
let months =times.getMonth()
let dates = times.getDate() < 10 ? '0' + times.getDate() : times.getDate()
this.inYear = years + '.' + months + '.' + dates
// 星期
let inday = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
let day = times.getDay();
this.inDay = inday[day - 1]
// // 时间
let hours = times.getHours();
let minutes = times.getMinutes();
minutes = minutes < 10 ? '0' + minutes : minutes;
let seconds = times.getSeconds();
seconds = seconds < 10 ? '0' + seconds : seconds;
this.inTime = hours + ':' + minutes + ':' + seconds;
}, 1000)
}
}
</script>
<style lang="scss">
.box{
width: 300px;
height: 100px;
background: #426ab3;
margin: 50px auto;
text-align: center;
line-height: 100px;
font-size: 40px;
color: #fff;
}
</style>