要求是:
不足一分钟:刚刚,
满一分钟不足24小时:xx分钟前
过了0点:昨天,2天前、3天前
超过三天:08-01(月-日)
谁可以帮我改一下吗?
这是我以前用的方法:
getDateDiff(dateTimeStamp) { //dateTimeStamp是一个时间毫秒,注意时间戳是秒的形式,在这个毫秒的基础上除以1000,就是十位数的时间戳。13位数的都是时间毫秒。
var result = ''
var minute = 1000 * 60
var hour = minute * 60
var day = hour * 24
var month = day * 30
var now = new Date().getTime()
var diffValue = now - dateTimeStamp
if (diffValue < 0) return
var monthC = diffValue / month
var weekC = diffValue / (7 * day)
var dayC = diffValue / day
var hourC = diffValue / hour
var minC = diffValue / minute
if (monthC >= 1) {
result = "" + parseInt(monthC) + "月前"
}
else if (weekC>=1) {
result = "" + parseInt(weekC) + "周前"
}
else if (dayC >= 1) {
result = ""+ parseInt(dayC) + "天前"
}
else if (hourC >= 1){
result = "" + parseInt(hourC) + "小时前"
}
else if (minC >= 1) {
result = ""+ parseInt(minC) + "分钟前"
} else {
result = "刚刚"
}
return result
}