欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

时间过滤器(几天前,几个月前)解析

程序员文章站 2022-10-17 09:59:26
时间过滤器(几天前,几个月前) //时间过滤器2 function getdatediff(datetimestamp) { var paddate = function(va) { va = va...

时间过滤器(几天前,几个月前)

//时间过滤器2
function getdatediff(datetimestamp) {
var paddate = function(va) {
va = va < 10 '' + va : va;
return va
}
var minute = 1000 * 60;
var hour = minute * 60;
var day = hour * 24;
var halfamonth = day * 15;
var month = day * 30;
var now = new date().gettime();
var oldtime = new date(datetimestamp.replace(/-/g, '/').replace(/t/g, ' ').substr(0, 19)).gettime()
var diffvalue = now - oldtime;
if(diffvalue < 0) {
return;
}
var monthc = diffvalue / month;
var weekc = diffvalue / (7 * day);
var dayc = diffvalue / day;
var hourc = diffvalue / hour;
var minc = diffvalue / minute;
// if(monthc >= 1) {
// result = "" + parseint(monthc) + "月前";
// } else if(weekc >= 1) {
// result = "" + parseint(weekc) + "周前";
// } else
if(dayc >= 3) {
var regtime = datetimestamp.replace(/-/g, '/').replace(/t/g, ' ');
var time = regtime.substr(0, 19);
var value = new date(time);
var year = value.getfullyear();
var month = paddate(value.getmonth() + 1);
var day = paddate(value.getdate());
var hour = paddate(value.gethours());
var minutes = paddate(value.getminutes());
var seconds = paddate(value.getseconds());
result = year + '.' + month + '.' + day;
} else if(dayc >= 1) {
result = "" + parseint(dayc) + "天前";
} else if(hourc >= 1) {
result = "" + parseint(hourc) + "小时前";
} else if(minc >= 1) {
result = "" + parseint(minc) + "分钟前";
} else {
result = "刚刚";
}

return result;
}