export var getDateDiff = function (dateTimeStamp) {
if(dateTimeStamp){
// 时间字符串转时间戳
var timestamp = new Date(dateTimeStamp).getTime();
var minute = 1000 * 60;
var hour = minute * 60;
var day = hour * 24;
var now = new Date().getTime();
var diffValue = now - timestamp;
var result;
if (diffValue < 0) {
return;
}
var dayC = diffValue / day;
var hourC = diffValue / hour;
var minC = diffValue / minute;
if (dayC >= 2) {
result = dateTimeStamp.split(" ")[0];
}else if (dayC < 2 && dayC > 1) {
result = "昨天";
} else if (hourC >= 1) {
result = "" + parseInt(hourC) + "小时前";
} else if (minC >= 1) {
result = "" + parseInt(minC) + "分钟前";
} else
result = "刚刚";
return result;
}else{
return ''
}
}
js 时间转换 刚刚、几分钟前、几小时前、昨天
于 2022-09-08 10:20:19 首次发布