update Time logic

This commit is contained in:
梁灏 2018-05-28 14:24:08 +08:00
parent 6918b81d2c
commit 28295360a8
2 changed files with 6 additions and 8 deletions

View file

@ -9,7 +9,7 @@
export default { export default {
data () { data () {
return { return {
ddd: new Date('2019-05-28 14:12:00') ddd: new Date('2018-04-27 14:23:00')
}; };
}, },
computed: {}, computed: {},

View file

@ -3,9 +3,9 @@
* @returns {Boolean} * @returns {Boolean}
*/ */
// const isMillisecond = timeStamp => { // const isMillisecond = timeStamp => {
// const timeStr = String(timeStamp); // const timeStr = String(timeStamp)
// return timeStr.length > 10; // return timeStr.length > 10
// }; // }
/** /**
* @param {Number} timeStamp 传入的时间戳 * @param {Number} timeStamp 传入的时间戳
@ -49,7 +49,6 @@ const getDate = (timeStamp, startType) => {
*/ */
export const getRelativeTime = timeStamp => { export const getRelativeTime = timeStamp => {
// 判断当前传入的时间戳是秒格式还是毫秒 // 判断当前传入的时间戳是秒格式还是毫秒
// const IS_MILLISECOND = isMillisecond(timeStamp);
const IS_MILLISECOND = true; const IS_MILLISECOND = true;
// 如果是毫秒格式则转为秒格式 // 如果是毫秒格式则转为秒格式
if (IS_MILLISECOND) Math.floor(timeStamp /= 1000); if (IS_MILLISECOND) Math.floor(timeStamp /= 1000);
@ -73,9 +72,8 @@ export const getRelativeTime = timeStamp => {
else if (diff > 3599 && diff <= 86399) resStr = Math.floor(diff / 3600) + '小时' + dirStr; else if (diff > 3599 && diff <= 86399) resStr = Math.floor(diff / 3600) + '小时' + dirStr;
// 多于23小时59分钟59秒少于等于29天59分钟59秒 // 多于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.floor(diff / 86400) + '天' + dirStr;
// 多于29天59分钟59秒少于364天23小时59分钟59秒 // 多于29天59分钟59秒少于364天23小时59分钟59秒且传入的时间戳早于当前
else if (diff > 2623859 && diff <= 31567859) resStr = getDate(timeStamp); else if (diff > 2623859 && diff <= 31567859 && IS_EARLY) resStr = getDate(timeStamp);
// 多于364天23小时59分钟59秒
else resStr = getDate(timeStamp, 'year'); else resStr = getDate(timeStamp, 'year');
return resStr; return resStr;
}; };