?% '###################################################################### '## ZeroASP.Time.asp '## ------------------------------------------------------------------- '## Feature : ZeroASP Class '## Author : Ayu(kinsc@139.com) '## Update Date : 2018-11-09 '## Description : ZeroASP Extend Class '## '###################################################################### Class ZeroASP_Time Private Sub Class_Initialize() Dim ZeroASP_Time ZeroASP_Time = "ZeroASP应用框架 - 扩展? End Sub '日期标准? Public Function Dates(ByVal TimeStr,ByVal Types) Dim D_Year,D_Month,D_Day Dim D_Hour,D_Minute,D_Second If TimeStr = "" Or IsNull(TimeStr) Then TimeStr = Now() End If If Not (IsDate(TimeStr)) Then Dates = "" Exit Function End If D_Year = Year(TimeStr) D_Month = Month(TimeStr) D_Day = Day(TimeStr) D_Hour = Hour(TimeStr) D_Minute = Minute(TimeStr) D_Second = Second(TimeStr) If Len(D_Month) < 2 Then D_Month = "0" & D_Month If Len(D_Day) < 2 Then D_Day = "0" & D_Day If Len(D_Hour) < 2 Then D_Hour = "0" & D_Hour If Len(D_Minute) < 2 Then D_Minute = "0" & D_Minute If Len(D_Second) < 2 Then D_Second = "0" & D_Second Select Case Types Case 1 '2000-10-10-23:45:45 Dates = D_Year & "-" & D_Month & "-" & D_Day & "-" & D_Hour & ":" & D_Minute & ":" & D_Second Case 2 '2000?0?0?3?5?5? Dates = D_Year & "? & D_Month & "? & D_Day & "? & D_Hour & "? & D_Minute & "? & D_Second & "? Case 3 '10/10 Dates = D_Month & "/" & D_Day Case 4 '2000-10-10 Dates = D_Year & "-" & D_Month & "-" & D_Day Case 5 '2000?0?0? Dates = D_Year & "? & D_Month & "? & D_Day & "? Case 6 '20001010102536 Dates = D_Year & D_Month & D_Day & D_Hour & D_Minute & D_Second Case 7 '2000/10/10 Dates = D_Year & "/" & D_Month & "/" & D_Day Case 8 '20001010 Dates = D_Year & D_Month & D_Day Case 9 '200010 Dates = D_Year & D_Month Case 10 '2000_10_10 Dates = D_Year & "_" & D_Month & "_" & D_Day Case 11 '2000 Dates = D_Year Case 12 '1010 Dates = D_Month & D_Day Case 13 '10? Dates = D_Day & "? Case 14 '2000-10-10 23:45:45 Dates = D_Year & "-" & D_Month & "-" & D_Day & " " & D_Hour & ":" & D_Minute & ":" & D_Second Case 15 '23:45:45 Dates = D_Hour & ":" & D_Minute & ":" & D_Second Case Else End Select Dates = Dates End Function '获取本月天数 Public Function TDays(ByVal tDate) Dim dt1,dt2 tDate = Zasp.Times.Dates(tDate,14) dt1 = CDate(Year(tDate) & "-" & Month(tDate) & "-1") '得到本月第一? dt2 = DateAdd("m",1,dt1) '得到下个月第一? TDays = DateDiff("d",dt1,dt2) '得到两个月的? End Function '获取当天星期? Public Function TWeek(ByVal ThisDay) If ThisDay <> "" And IsDate(ThisDay) Then Dim CharWeek CharWeek = Weekday(ThisDay) 'Weekday函数一周的天数的数?介于 1 ?7 之间 Select Case CharWeek Case 1 '国际标准时间规定每周第一天为星期? TWeek = "星期? Case 2 TWeek = "星期一" Case 3 TWeek = "星期? Case 4 TWeek = "星期? Case 5 TWeek = "星期? Case 6 TWeek = "星期? Case 7 TWeek = "星期? End Select End If End Function '时间过了多久 Public Function TimePass(Byval sTheDate) ' 格式化显示时间为几个?几天?几小时前,几分钟前,或几秒前 Dim iSeconds,iMinutes,iHours,iDays 'sTheDate = CDate(sTheDate) iSeconds = DateDiff("s",sTheDate,Zasp.Times.Dates(Now(),14)) 'd/h/n/s iMinutes = Int(iSeconds / 60) iHours = Int(iSeconds / 3600) iDays = Int(iSeconds / 86400) If iDays > 60 Then '大于2个月则显示日? TimePass = Zasp.Times.Dates(sTheDate,4) ElseIf iDays > 30 Then TimePass = "1个月? ElseIf iDays > 14 Then TimePass = "2周前" ElseIf iDays > 7 Then TimePass = "1周前" ElseIf iDays > 1 Then TimePass = iDays & "天前" ElseIf iHours > 1 Then TimePass = iHours & "小时? ElseIf iMinutes > 1 Then TimePass = iMinutes & "分钟? ElseIf iSeconds >= 1 Then TimePass = iSeconds & "秒前" Else TimePass = "1秒前" End If End Function '把标准时间转换为UNIX时间? '参数:strTime:要转换的时间;intTimeZone:该时间对应的时? '返回值:strTime相对?970??日午?点经过的秒数 '示例:ToUnixTime("2008-5-23 10:51:0", +8),返回值为1211511060 Public Function ToUnixTime(Byval strTime,Byval intTimeZone) If IsEmpty(strTime) Or Not IsDate(strTime) Then strTime = Zasp.Times.Dates(Now(),14) If IsEmpty(intTimeZone) Or Not IsNumeric(intTimeZone) Then intTimeZone = 0 ToUnixTime = DateAdd("h",-intTimeZone,strTime) ToUnixTime = DateDiff("s","1970-01-01 00:00:00",ToUnixTime) End Function '把UNIX时间戳转换为标准时间 '参数:intTime:要转换的UNIX时间戳;intTimeZone:该时间戳对应的时区 '返回值:intTime所代表的标准时? '示例:FromUnixTime("1211511060", +8),返回?008-5-23 10:51:0 Public Function UnixTimeTo(Byval intTime,Byval intTimeZone) If IsEmpty(intTime) Or Not IsNumeric(intTime) Then UnixTimeTo = Zasp.Times.Dates(Now(),14) Exit Function End If If IsEmpty(intTime) Or Not IsNumeric(intTimeZone) Then intTimeZone = 0 UnixTimeTo = DateAdd("s",intTime,"1970-01-01 00:00:00") UnixTimeTo = DateAdd("h",intTimeZone,UnixTimeTo) End Function '当前时间标准化,带毫秒显? Public Function ZNow() Dim NowDate,NowTime,D_Time,D_Hour,D_Minute,D_Second,D_Millisecond NowDate = Zasp.Times.Dates(Now(),4) '2016-07-03 NowTime = Timer() 'Timer 函数可返回午?12 时(12:00 AM)以后已经过去的秒数? D_Time = Split(NowTime,".")(0) '获取秒数 D_Hour = Int(D_Time / 3600) '获取小时 If Len(D_Hour) < 2 Then D_Hour = "0" & D_Hour D_Minute = Int((D_Time Mod 3600) / 60) '获取分钟 If Len(D_Minute) < 2 Then D_Minute = "0" & D_Minute D_Second = (D_Time Mod 3600) Mod 60 '获取? If Len(D_Second) < 2 Then D_Second = "0" & D_Second D_Millisecond = Split(NowTime,".")(1) '获取毫秒 If Len(D_Millisecond) < 1 Then D_Millisecond = "000" '相同长度 ElseIf Len(D_Millisecond) = 1 Then D_Millisecond = D_Millisecond & "00" '相同长度 ElseIf Len(D_Millisecond) = 2 Then D_Millisecond = D_Millisecond & "0" '相同长度 ElseIf Len(D_Millisecond) = 3 Then D_Millisecond = D_Millisecond '相同长度 ElseIf Len(D_Millisecond) > 3 Then D_Millisecond = Left(D_Millisecond,3) '相同长度 End If ZNow = NowDate & " " & D_Hour & ":" & D_Minute & ":" & D_Second & "." & D_Millisecond End Function End Class %>