ASP 格式化显示时间为几个月,几天前,几小时前,几分钟前,或几秒前
实现函数代码
Function DateStringFromNow(Byval sTheDate)
' 格式化显示时间为几个月,几天前,几小时前,几分钟前,或几秒前
Dim iSeconds, iMinutes, iHours, iDays
iSeconds = DateDiff("s", sTheDate, Now()) 'd/h/n/s
iMinutes = Int(iSeconds/60)
iHours = Int(iSeconds/3600)
iDays = Int(iSeconds/86400)
If iDays > 60 Then
DateStringFromNow = sTheDate
ElseIf iDays > 30 Then
DateStringFromNow = "1个月前"
ElseIf iDays > 14 Then
DateStringFromNow = "2周前"
ElseIf iDays > 7 Then
DateStringFromNow = "1周前"
ElseIf iDays > 1 Then
DateStringFromNow = iDays & "天前"
ElseIf iHours > 1 Then
DateStringFromNow = iHours & "小时前"
ElseIf iMinutes > 1 Then
DateStringFromNow = iMinutes & "分钟前"
ElseIf iSeconds >= 1 Then
DateStringFromNow = iSeconds & "秒前"
Else
DateStringFromNow = "1秒前"
End If
End Function
✄-------------✎博主签名------------✄
一个人,只有当他的灵魂真正撼动了、刺痛了,他的智慧才可能被空前的发掘。人一旦变得清醒、理智起来,他就一步步靠近了成熟。