为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
ITMISS 2019-03-15 09:54:19
我想把图中红色框转为多少天前 如下方法 <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> 空白,也不报错 重新上传
查看完整描述

4 回答

  • 4 回答
  • 0 关注
  • 490 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信