用于显示距离当前时间间隔的asp函数,有不足的地方麻烦指出来,谢谢

来源:互联网 发布:骤风软件 编辑:程序博客网 时间:2024/04/27 17:18

<%
'// 还可以加上半个月前,半年前,什么的自己再发挥下吧,~_~
Function Time_Interval(times,nows) '// 发布时间距离现在 time 数据库取出的时间,nows对应nows()
y=year(times):m=month(times):d=day(times)
limit_s=DateDiff("s",times,now)  '// 距离现在秒数
limit_n=DateDiff("n",times,now)  '// 距离现在分钟数
limit_h=DateDiff("h",times,now)  '// 距离现在小时数
limit_d=DateDiff("d",times,now)  '// 距离现在天数
limit_m=DateDiff("m",times,now)  '// 距离现在月数
 if y=year(now) then '// 判断是不是当年的记录
  if m&d=month(now)&day(now) then '// 判断是不是当天的记录
   if limit_s < 60 then
    Time_Interval=limit_s&"秒前"
   elseif limit_n >= 1 and limit_n < 60 then
    Time_Interval=limit_n&"分钟前"
   elseif limit_h >= 1 and limit_h < 12 then '// 12小时后的,都显示为今天
    Time_Interval=limit_h&"小时前"
   else
    Time_Interval="今天"
   end if
  else
   if limit_m <= 1 then
    Time_Interval=limit_d & "天前"
   else
    Time_Interval=limit_m & "个月前"
   end if
  end if
 else
  Time_Interval=y&"-"&m&"-"&d
 end if
End Function
%>
<%=Time_Interval("2011-10-1 10:58:00",now)%>

原创粉丝点击