vb 代码
- 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 >60Then
- DateStringFromNow= sTheDate
- ElseIf iDays >30Then
- DateStringFromNow="1个月前"
- ElseIf iDays >14Then
- DateStringFromNow="2周前"
- ElseIf iDays >7Then
- DateStringFromNow="1周前"
- ElseIf iDays >1Then
- DateStringFromNow= iDays "天前"
- ElseIf iHours >1Then
- DateStringFromNow= iHours "小时前"
- ElseIf iMinutes >1Then
- DateStringFromNow= iMinutes "分钟前"
- ElseIf iSeconds >=1Then
- DateStringFromNow= iSeconds "秒前"
- Else
- DateStringFromNow="1秒前"
- EndIf
- End Function
评论前必须登录!
注册