微信朋友圈左下角的发表时间怎么改
发布于 6 年前 作者 nafu 7107 次浏览 来自 问答

后台给的是一个时间戳,微信朋友圈左下角的发表时间怎么改,就像手机微信朋友圈的动态发表时间。

将时间戳改为当前发表时间,列如两小时前,7小时前,一天前。

2 回复

当前时间戳”减去“发表时间戳”

//不满60,按秒

//满60不满3600,除60取整,按分

以上不满3600,可以为“刚刚”

满3600不满86400,除3600取整,按时

超过86400,86400取整,按天

以下可以按日期

timess 时间戳

//计算时间差

function timesshow(timess){

    var time1=new Date();  //现在时间

    var time2=new Date(timess);  //结束时间

    var time3=time1.getTime()-time2.getTime()  //时间差的毫秒数

    //计算出相差星期数

    var weeks=Math.floor(time3/(7*24*3600*1000));

    //计算出相差天数

    var days=Math.floor(time3/(24*3600*1000));

    //计算出小时数

    var leave1=time3%(24*3600*1000)    //计算天数后剩余的毫秒数

    var hours=Math.floor(leave1/(3600*1000));

    //计算相差分钟数

    var leave2=leave1%(3600*1000)        //计算小时数后剩余的毫秒数

    var minutes=Math.floor(leave2/(60*1000));

    //计算相差秒数

    var leave3=leave2%(60*1000)      //计算分钟数后剩余的毫秒数

    var seconds=Math.round(leave3/1000);

    if(weeks!=0){

        return formatDate(timess);//自己解析时间戳

    }else if(weeks==0&&days!=0){

        return days+“天前发表”;

    }else if(weeks==0&&days==0&&hours!=0){

        return  hours+“小时前发表”;

    }else if(weeks==0&&days==0&&hours==0&&minutes!=0){

        return  minutes+" 分钟前发表";

    }else if(weeks==0&&days==0&&hours==0&&minutes==0&&seconds!=0){

        return “刚发表:”+seconds+" 秒";

    }

}

//处理时间戳

function formatDate(timessnow) {

    var now=new Date(timessnow);

    var year = now.getFullYear();

    var month = now.getMonth() < 9 ? “0” + (now.getMonth() + 1) : now.getMonth() + 1;

    var date = now.getDate() < 10 ? “0” + now.getDate() : now.getDate();

    var hour = now.getHours() < 10 ? “0” + now.getHours() : now.getHours();

    var minute = now.getMinutes() < 10 ? “0” + now.getMinutes() : now.getMinutes();

    var second = now.getSeconds() < 10 ? “0” + now.getSeconds() : now.getSeconds();

    return year + “年” + month + “月” + date + "日 " +

    hour + “:” + minute + “:” + second;

}

--------------------- 

作者:书香代码 

来源:CSDN 

原文:https://blog.csdn.net/u010138825/article/details/50553673?utm_source=copy 

版权声明:本文为博主原创文章,转载请附上博文链接!

回到顶部