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;
}