update Time
This commit is contained in:
parent
77669e5d8f
commit
37086acc1c
2 changed files with 18 additions and 17 deletions
|
@ -1,20 +1,20 @@
|
|||
<template>
|
||||
<div>
|
||||
<Time :time="1526608921" />
|
||||
<Time :time="1652839997" />
|
||||
<Time :time="ddd" :interval="1" />
|
||||
|
||||
<Time time="2018-06-20T13:09:14.000Z" />
|
||||
<Time :time="time1" />
|
||||
<br>
|
||||
<Time :time="time2" />
|
||||
<br>
|
||||
<Time :time="time3" :interval="60" />
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
data () {
|
||||
return {
|
||||
ddd: new Date()
|
||||
};
|
||||
},
|
||||
computed: {},
|
||||
methods: {}
|
||||
};
|
||||
</script>
|
||||
time1: (new Date()).getTime() - 60 * 1 * 1000,
|
||||
time2: (new Date()).getTime() - 86400 * 3 * 1000,
|
||||
time3: new Date()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* @returns {Boolean} 传入的时间戳是否早于当前时间戳
|
||||
*/
|
||||
const isEarly = (timeStamp, currentTime) => {
|
||||
return timeStamp < currentTime;
|
||||
return timeStamp <= currentTime;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -65,13 +65,14 @@ export const getRelativeTime = timeStamp => {
|
|||
let resStr = '';
|
||||
const dirStr = IS_EARLY ? '前' : '后';
|
||||
// 少于等于59秒
|
||||
if (diff <= 59) resStr = parseInt(diff) + '秒' + dirStr;
|
||||
if (diff < 1) resStr = '刚刚';
|
||||
else if (diff <= 59) resStr = parseInt(diff) + '秒' + dirStr;
|
||||
// 多于59秒,少于等于59分钟59秒
|
||||
else if (diff > 59 && diff <= 3599) resStr = Math.floor(diff / 60) + '分钟' + dirStr;
|
||||
else if (diff > 59 && diff <= 3599) resStr = Math.ceil(diff / 60) + '分钟' + dirStr;
|
||||
// 多于59分钟59秒,少于等于23小时59分钟59秒
|
||||
else if (diff > 3599 && diff <= 86399) resStr = Math.floor(diff / 3600) + '小时' + dirStr;
|
||||
else if (diff > 3599 && diff <= 86399) resStr = Math.ceil(diff / 3600) + '小时' + dirStr;
|
||||
// 多于23小时59分钟59秒,少于等于29天59分钟59秒
|
||||
else if (diff > 86399 && diff <= 2623859) resStr = Math.floor(diff / 86400) + '天' + dirStr;
|
||||
else if (diff > 86399 && diff <= 2623859) resStr = Math.ceil(diff / 86400) + '天' + dirStr;
|
||||
// 多于29天59分钟59秒,少于364天23小时59分钟59秒,且传入的时间戳早于当前
|
||||
else if (diff > 2623859 && diff <= 31567859 && IS_EARLY) resStr = getDate(timeStamp);
|
||||
else resStr = getDate(timeStamp, 'year');
|
||||
|
|
Loading…
Add table
Reference in a new issue