我想把图中红色框转为多少天前
![clipboard.png https://img3.mukewang.com/5c8f441b000110db03930685.jpg](https://img3.mukewang.com/5c8f441b000110db03930685.jpg)
如下方法
<script>
function replyTime(value) {
if (!value) {
return ''
}
let date = new Date(value)
let time = new Date().getTime() - date.getTime() // 现在的时间-传入的时间 = 相差的时间(单位 = 毫秒)
if (time < 0) {
return ''
} else if ((time / 1000 < 30)) {
return '刚刚'
} else if (time / 1000 < 60) {
return parseInt((time / 1000)) + '秒前'
} else if ((time / 60000) < 60) {
return parseInt((time / 60000)) + '分钟前'
} else if ((time / 3600000) < 24) {
return parseInt(time / 3600000) + '小时前'
} else if ((time / 86400000) < 31) {
return parseInt(time / 86400000) + '天前'
} else if ((time / 2592000000) < 12) {
return parseInt(time / 2592000000) + '月前'
} else {
return parseInt(time / 31536000000) + '年前'
}
}
console.log(replyTime('2018-04-26T09:51:19.808Z')) //22前天
</script>
![clipboard.png https://img2.mukewang.com/5c8f441c0001b3e308000270.jpg](https://img3.mukewang.com/5c8f441c0001b3e305000169.jpg)
![clipboard.png https://img.mukewang.com/5c8f441e00015eed08000439.jpg](https://img1.mukewang.com/5c8f441e00015eed05000275.jpg)
空白,也不报错
![clipboard.png https://img3.mukewang.com/5c8f441f0001249f04280725.jpg](https://img3.mukewang.com/5c8f441f0001249f04280725.jpg)
重新上传
![clipboard.png https://img.mukewang.com/5c8f44210001482208000620.jpg](https://img2.mukewang.com/5c8f44210001482205000388.jpg)