[javascript]代码库
function computeTime(replyTime){
var nowTime = Date.parse(new Date());//获取当前unix时间戳
var tempTime = nowTime - replyTime;
var stepflag = Math.round(tempTime/(1000*60));//相差N分钟
var result;
if(stepflag < 3)
result = "刚刚";
else if(stepflag >= 3 && stepflag < 60)
result = stepflag + "分钟前";
else if(stepflag >= 60 && stepflag < 1440)
result = Math.round(stepflag/60) + "小时前";
else if(stepflag >= 1440 && stepflag < 43200)
result = Math.round(stepflag/(60*24))+ "天前";
else
result = Math.round(stepflag/(60*24*30))+ "月前";
return result;
}