返回微信的多少分钟前,多少小时前,多少天前小方法
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