使用到了momentjs,官网 点击前往

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import moment from 'moment'	

// 人性化时间过滤 stamp 时间戳
common.humanizedTimeFilter = function (stamp) {
const minute = 1000 * 60
const hour = minute * 60
const day = hour * 24
const now = new Date().getTime() - 28800000
let result
const diffValue = now - stamp
if (diffValue < 0) {
return ''
}
const dayC = diffValue / day
const hourC = diffValue / hour
const minC = diffValue / minute
if (dayC === 1) {
result = '昨天'
return result
}
if (dayC > 1 && dayC < 30) {
result = parseInt(dayC) + '天前'
return result
}
if (dayC < 1) {
if (hourC >= 1) {
result = parseInt(hourC) + '小时前'
} else if (minC >= 1) {
result = parseInt(minC) + '分钟前'
} else {
result = '刚刚'
}
return result
} else {
const pattern = 'YYYY-MM-DD'
return moment(stamp + 28800000).format(pattern)
}
}

使用:

1
common.humanizedTimeFilter( moment(r.update_status_at).valueOf())