<style lang="less">
</style>
<template>
<view class="container">
<text class="day">{{day}}天{{h}}小时{{m}}分{{s}}秒</text>
</view>
</template>
<script>
import wepy from 'wepy'
export default class me extends wepy.page {
config = {
navigationBarTitleText: 'me'
}
onLoad() {
console.log('onLoad')
}
onReady() {
let getTime = () => {
let stopDate = +new Date('2018-10-24')// 获取截至时间戳(.getTime()==+)
let nowDate = +new Date()// 获取当前时间戳
let dTime = nowDate - stopDate// 计算时间差
let s = dTime / 1000// 计算秒
let m = s / 60// 计算分钟
let h = m / 60// 计算小时
let day = h / 24// 计算天
this.setData({
day: parseInt(day),
h: parseInt(h % 24),
m: parseInt(m % 60),
s: parseInt(s % 60)
})
}
getTime()
setInterval(() => {
getTime()
}, 1000)
}
}
</script>
网友评论