小程序模板網(wǎng)

小程序?qū)崿F(xiàn)微信朋友圈時(shí)間顯示效果

發(fā)布時(shí)間:2021-06-19 18:07 所屬欄目:小程序開(kāi)發(fā)教程

程序?qū)崿F(xiàn)微信朋友圈時(shí)間顯示效果:

1分鐘前,2分鐘前,···,59分鐘前,1小時(shí)前,2小時(shí)前,···,23小時(shí)前,一天前,2天前,2019-06-21 等等...

 

相關(guān)代碼如下:


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


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開(kāi)源 碼云倉(cāng)庫(kù):starfork
本文地址:http://22321a.com/wxmini/doc/course/26570.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢:800182392 點(diǎn)擊咨詢
QQ在線咨詢