标签:天前 code bsp ret math create new last col
某条消息发布后,距离当前时间多久的时间显示
1 //显示发布时间的函数 2 function pastTime(_createTime) { 3 //var createTime = _createTime.substr(0, _createTime.lastIndexOf(" ")) //不能包含毫秒,如果有毫秒,进行截取 4 var nowTime = new Date(); 5 var cTime = new Date(_createTime); 6 var result = parseInt((nowTime - cTime) / 1000 / 60); //分钟数 7 if (result < 0) { 8 result = Math.abs(720 + result); 9 } 10 var resultStr = result + "分钟前"; 11 if (result == 0) { 12 resultStr = "刚刚发布" 13 } 14 //如需显示“月”,“年” 在此处添加if...else 15 if (result >= 10080) { 16 result = parseInt(result / 60*24*7); //周 17 resultStr = result + "周前" 18 } else if (result >= 1440) { 19 result = parseInt(result / 60*24); //天 20 resultStr = result + "天前" 21 } else if (result >= 60) { 22 result = parseInt(result / 60); //小时 23 resultStr = result + "小时前" 24 } 25 return resultStr; 26 }
标签:天前 code bsp ret math create new last col
原文地址:http://www.cnblogs.com/fengguohoudejiyi/p/7631938.html