小程序,如何给数据渲染时加一个方法,改变他的值,如下图和代码

我想把图中红色框转为多少天前

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>

https://img2.mukewang.com/5c8f441c0001b3e308000270.jpg

https://img.mukewang.com/5c8f441e00015eed08000439.jpg

空白,也不报错

https://img3.mukewang.com/5c8f441f0001249f04280725.jpg

重新上传

https://img.mukewang.com/5c8f44210001482208000620.jpg

ITMISS
浏览 491回答 4
4回答
打开App,查看更多内容
随时随地看视频慕课网APP