export const getDateDiff = (dateTime) => {
const minute = 1000 * 60;
const hour = minute * 60;
const day = hour * 24;
const month = day * 30;
const now = new Date().getTime();
const diffValue = now - dateTime;
const monthC = diffValue / month;
const weekC = diffValue / (7 * day);
const dayC = diffValue / day;
const hourC = diffValue / hour;
const minC = diffValue / minute;
let timeText;
if (monthC >= 1) {
timeText= parseInt(monthC) + '个月前';
} else if (weekC >= 1) {
timeText= parseInt(weekC) + '周前';
} else if (dayC >= 1) {
timeText= parseInt(dayC) + '天前';
} else if (hourC >= 1) {
timeText= parseInt(hourC) + '个小时前';
} else if (minC >= 1) {
timeText= parseInt(minC) + '分钟前';
} else {
timeText= '刚刚';
}
return timeText;
};
根据当前时间分装的方法,刚刚,几分钟前,几个小时前,几天前,几周前,几个月前