一聚教程网:一个值得你收藏的教程网站

热门教程

asp 计算时间日期

时间:2022-07-02 23:03:08 编辑:袖梨 来源:一聚教程网

  Public Function TimeToDiff(DateTime)
  If IsDate(DateTime) Then
   Dim tSecond:tSecond=DateDiff("s",DateTime,Now())
   If tSecond<60 Then'//一分钟内
    TimeToDiff="刚刚"
   End If
   If tSecond>=60 And tSecond<3600 Then'//一小时内
    TimeToDiff=DateDiff("n",DateTime,Now())&"分钟前"
   End If
   If tSecond>=3600 And tSecond<86400 Then'//一天内
    TimeToDiff=DateDiff("h",DateTime,Now())&"小时前"
   End If
   If tSecond>=86400 And tSecond<2592000 Then'//一个月内
    TimeToDiff=DateDiff("d",DateTime,Now())&"天前"
   End If
   If tSecond>=2592000 And tSecond<31536000 Then'//一年内
    TimeToDiff=DateDiff("m",DateTime,Now())&"个月前"
   End If
   If tSecond>=31536000 Then'//其它
    TimeToDiff=DateDiff("yyyy",DateTime,Now())&"年前"
   End If
  Else
   TimeToDiff="N天前"
  End If
 End Function
 
'调用方法
call TimeToDiff(Now()))

热门栏目