zoukankan      html  css  js  c++  java
  • 返回微信的多少分钟前,多少小时前,多少天前小方法

    function js_strto_times(str_time){  
        var new_str = str_time.replace(/:/g,"-");  
        new_str = new_str.replace(/ /g,"-");  
        var arr = new_str.split("-");  
        var datum = new Date(Date.UTC(arr[0],arr[1]-1,arr[2],arr[3]-8,arr[4]));  
        return strtotime = datum.getTime();
    } 
    function  formatDate(dateTimeStamp){
        var date = js_strto_times(dateTimeStamp);
        var commondate = dateTimeStamp;
        var now = new Date().getTime();
        //console.log(now);
        var diffValue = now - date;
        var monthC =diffValue/month;
        var weekC =diffValue/(7*day);
        var dayC =diffValue/day;
        var hourC =diffValue/hour;
        var minC =diffValue/minute;
        if(dayC>=1){
            result=commondate;
        }
        else if(hourC>=1){
            if(hourC >=10){
                result = commondate;
            }else{
            result=parseInt(hourC) +"个小时前";
            }
        }
        else if(minC>=1){
            result=parseInt(minC) +"分钟前";
        }else
        result="刚刚";
        return result;
    }

    需求是超过10小时显示具体时间 10小时内显示多少小时前 多少分钟前

    服务端返回的格式是2016-10-28 00:00

  • 相关阅读:
    Hive 2.1.1安装配置
    vi / vim 删除以及其它命令
    『MySQL』时间戳转换
    update 中实现子查询
    hive lateral view 与 explode详解
    xpath定位方法详解
    Python int与string之间的转化
    ORM、SQLAchemy
    python bottle 简介
    python wsgi 简介
  • 原文地址:https://www.cnblogs.com/junwu/p/6006718.html
Copyright © 2011-2022 走看看