Applet implement micro-channel circle of friends time display:
1 minute ago, 5 minutes ago, ···, 59 minutes before, 1 hour before, 2 hours before, ..., 23 hours before the day before, two days before, and so on ... 2019-06-21
Related code is as follows:
getTime() { let start = '2019-6-21 22:41:00' let nowTime = new Date() let oldTime = new Date(start) let diff = Math.floor((nowTime - oldTime)/1000/60) let time = start if(diff <= 59){ Time = the diff + 'ago' } the else IF (the diff <= 60 * 24-1 ) { Time = Math.floor (the diff / 60) + 'hours before' } the else IF (the diff <= 60 * 24 * 3-1 ) { Time = Math.floor (the diff / 60/24) + 'before days' } the else { time = time.split(" ")[0] } return time }