2019-07-10格式化时间几天前,几分钟前等

var minute = 1000 * 60;
var hour = minute * 60;
var day = hour * 24;
var result = '';
var now = new Date().getTime();
var diffValue = now - new Date(value).getTime();//value是所需要处理的时间
if (diffValue < 0) {
    console.log("时间不对劲,服务器创建时间与当前时间不同步");
    return result = "刚刚";
}
var dayC = diffValue / day;
var hourC = diffValue / hour;
var minC = diffValue / minute;
if (parseInt(dayC) > 30) {
    result = "" + this.$format(dateTimeStamp, "yyyy-MM-dd");
} else if (parseInt(dayC) > 1) {
    result = "" + parseInt(dayC) + "天前";
} else if (parseInt(dayC) == 1) {
    result = "昨天";
} else if (hourC >= 1) {
    result = "" + parseInt(hourC) + "小时前";
} else if (minC >= 5) {
    result = "" + parseInt(minC) + "分钟前";
} else
    result = "刚刚";
return result;

你可能感兴趣的:(2019-07-10格式化时间几天前,几分钟前等)