欢迎加入EUCMS官方QQ交流群,与更多EUCMS用户一起讨论,共同发财!
QQ群:1222386格式:Format_Date_Friend(ByVal dt)
参数:
dt:指定要处理的时间参数。
代码:
Function Format_Date_Friend(ByVal dt)
应用:
Dim t_SECOND : t_SECOND = 1
Dim t_MINUTE : t_MINUTE = 60 * t_SECOND
Dim t_HOUR : t_HOUR = 60 * t_MINUTE
Dim t_DAY : t_DAY = 24 * t_HOUR
Dim t_MONTH : t_MONTH = 30 * t_DAY
Dim delta : delta = DateDiff("s", dt, Now)
Dim strTime : strTime = ""
If (delta < 1 * t_MINUTE) Then
If delta = 0 Then
strTime = "现在"
ElseIf delta = 1 Then
strTime = "1秒前"
Else
strTime = delta&"秒前"
End If
ElseIf (delta < 2 * t_MINUTE) Then
strTime = "1分钟前"
ElseIf (delta < 60 * t_MINUTE) Then
strTime = Round(delta / t_MINUTE)&"分钟前"
ElseIf (delta < 90 * t_MINUTE) Then
strTime = "1小时前"
ElseIf (delta < 24 * t_HOUR) Then
strTime = Round(delta / t_HOUR)&"小时前"
ElseIf (delta < 48 * t_HOUR) Then
strTime = "昨天"
ElseIf (delta < 30 * t_DAY) Then
strTime = Round(delta / t_DAY) & "天以前"
ElseIf (delta < 12 * t_MONTH) Then
Dim months
months = Round(delta / t_MONTH)
If months <= 1 Then
strTime = "1个月前"
Else
strTime = months & "个月前"
End If
Else
Dim years : years = Round((delta / t_DAY) / 365)
If years <= 1 Then
strTime = "1年前"
Else
strTime = years & "年以前"
End If
End If
Format_Date_Friend = strTime
End Function
Dim input,str
input="2020-09-04 12:08:35"
response.Write "之前时间是:"&input&"。距离现在是:"
response.Write Format_Date_Friend(input)
返回:之前时间是:2020-09-04 12:08:35。距离现在是:11小时前