mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-mobile.git
synced 2025-12-07 09:56:45 +08:00
2022年5月29日 从svn移到git
This commit is contained in:
69
components/time-show/time-show.vue
Normal file
69
components/time-show/time-show.vue
Normal file
@@ -0,0 +1,69 @@
|
||||
<template>
|
||||
<text style="font-size: 24upx;color: #999999;">{{showTime}}</text>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props:{
|
||||
css:{
|
||||
type:String,
|
||||
default:''
|
||||
},
|
||||
time:{
|
||||
type:String,
|
||||
default:''
|
||||
}
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
|
||||
}
|
||||
},
|
||||
computed:{
|
||||
showTime(){
|
||||
if(this.time!=null && this.time!=''){
|
||||
//console.log(this.time,'时间内容');
|
||||
let showStr='';
|
||||
let dt1=new Date(this.time.replace(/-/g,'/'));
|
||||
let dt2=new Date();
|
||||
var dateDiff = dt2.getTime() - dt1.getTime();//时间差的毫秒数
|
||||
var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000));//计算出相差天数
|
||||
var leave1=dateDiff%(24*3600*1000) //计算天数后剩余的毫秒数
|
||||
var hours=Math.floor(leave1/(3600*1000))//计算出小时数
|
||||
var leave2=leave1%(3600*1000) //计算小时数后剩余的毫秒数
|
||||
var minutes=Math.floor(leave2/(60*1000))//计算相差分钟数
|
||||
var leave3=leave2%(60*1000) //计算分钟数后剩余的毫秒数
|
||||
var seconds=Math.round(leave3/1000)
|
||||
if(dayDiff>31){
|
||||
let monthDiff=Math.floor(dayDiff/30);//以30天为一个月不够精准严谨
|
||||
if(monthDiff>12){
|
||||
let yearDiff=Math.floor(monthDiff/12);//获取相差的年份
|
||||
showStr=yearDiff+'年之前';
|
||||
}else{
|
||||
showStr=monthDiff+'个月之前';
|
||||
}
|
||||
}else{
|
||||
if(dayDiff>0){
|
||||
showStr=dayDiff+'天之前';
|
||||
}else if(hours>0){
|
||||
showStr=hours+'小时之前';
|
||||
}else if(minutes>0){
|
||||
showStr=minutes+'分钟之前';
|
||||
}else if(seconds>0){
|
||||
showStr=seconds+'秒之前';
|
||||
} else if(seconds == 0) {
|
||||
showStr='刚刚';
|
||||
}
|
||||
}
|
||||
return showStr;
|
||||
}else{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
Reference in New Issue
Block a user