小程序模板网

小程序实现微信朋友圈时间显示效果

发布时间:2021-06-19 18:07 所属栏目:小程序开发教程

程序实现微信朋友圈时间显示效果:

1分钟前,2分钟前,···,59分钟前,1小时前,2小时前,···,23小时前,一天前,2天前,2019-06-21 等等...

 

相关代码如下:


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 = diff + '分钟前'
    }else if(diff <= 60*24-1){
        time = Math.floor(diff / 60) + '小时前'
    }else if(diff <= 60*24*3-1){
        time = Math.floor(diff / 60 / 24) + '天前'
    }else{
        time = time.split(" ")[0]
    }
    return time
}


易优小程序(企业版)+灵活api+前后代码开源 码云仓库:starfork
本文地址:https://www.eyoucms.com/wxmini/doc/course/26570.html 复制链接 如需定制请联系易优客服咨询:800182392 点击咨询
QQ在线咨询