<template>
<view class="outer">
<view class="chai">
<image :class="type == 1?'fangda':''" v-if="type == 1" src="../../../static/images/weichai.png" mode=""></image>
<image :class="type == 2?'fangda':''" v-if="type == 2" src="../../../static/images/yikaiqiang.png" mode=""></image>
<image :class="type == 3?'fangda':''" v-if="type == 3" src="../../../static/images/qiangguang.png" mode=""></image>
<view class="" :class="type>0?'num':''">
{{nowTimer | formatDate}}
<countdown :is-day="false" :tip-text="' '" :day-text="' '" :hour-text="':'" :minute-text="':'" :second-text="' '"
:datatime="datatime"></countdown>
</view>
</view>
</view>
</template>
<script>
import countdown from "@/components/cz-countdown/cz-countdown.vue"
export default {
components:{
countdown
},
data() {
return {
datatime: 1619999999, // 获取截止时间
outTime:'2020/12/17 10:44:10',
nowTimer:'',
isshow:false,
money:0,
show:false,
tixianMId:''
};
},
onLoad(option) {
},
created() {
this.nowTimer = new Date(this.outTime).getTime() / 1000
console.log(this.nowTimer);
},
filters:{
formatDate:(nowTimer)=>{
let fromis = {
'year':'几年前',
'moth':'几个月前',
'day':'几天前',
'hour':'几小时前',
'minute':'几分钟前',
'second':'几秒前'
};
// 获取当前时间戳
let nowData = Date.now();
let second = Math.floor((nowData - parseInt(nowTimer))/1000);
let minute = Math.floor(second/60);
let hour = Math.floor(minute/60);
let day = Math.floor(hour/24);
let moth = Math.floor(day / 30);
let year = Math.floor(moth/12);
let oldType = '';
let oldValue = 0;
if(year>0){
oldType = 'year'
oldValue = year
}else if(moth>0){
oldType = 'moth'
oldValue = moth
}else if(day>0){
oldType = 'day'
oldValue = day
}else if(hour>0){
oldType = 'hour'
oldValue = hour
}else if(minute>0){
oldType = 'minute'
oldValue = minute
}else{
oldType = 'second'
oldValue = second === 0 ?(second = 1):second
}
return fromis[oldType].replace('几', oldValue);
}
},
methods:{
}
}
</script>
filters过滤时间
最新推荐文章于 2022-09-28 18:33:44 发布