'把标准时间转换为UNIX时间戳
Function ToUnixTime(strTime, intTimeZone) If IsEmpty(strTime) or Not IsDate(strTime) Then strTime = Now 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时间戳转换为标准时间
Function FromUnixTime(intTime, intTimeZone) If IsEmpty(intTime) or Not IsNumeric(intTime) Then FromUnixTime = Now() Exit Function End If If IsEmpty(intTime) or Not IsNumeric(intTimeZone) Then intTimeZone = 0 FromUnixTime = DateAdd("s", intTime, "1970-01-01 00:00:00") FromUnixTime = DateAdd("h", intTimeZone, FromUnixTime) End Function
'调用方法:
'示例:ToUnixTime("2009-12-05 12:52:25", +8),返回值为1259988745
'response.Write ToUnixTime("2009-12-05 12:52:25", +8)
'示例:FromUnixTime("1259988745", +8),返回值2009-12-05 12:52:25
'response.Write FromUnixTime("1259988745", +8)
'到当前时间=格林时间+8 Function UtctoBeijingtime(Str) Strim=DateDiff("s","1970-01-01 00:00:00",Str)'utc UtctoBeijingtime = DateAdd("s",Strim,"1970-01-01 08:00:00") End Function '到格林时间=当前时间-8 Function BeijingtimeToUtc(Str) Strim=DateDiff("s","1970-01-01 08:00:00",Str)'utc BeijingtimeToUtc = DateAdd("s",Strim,"1970-01-01 00:00:00") End Function '格式化阿里接口时间 Function AliToTime(t) dim y,m,d,h,mi,s AliToTime="" If IsDate(t)=False Then Exit Function y=cstr(year(t)) m=cstr(month(t)) If len(m)=1 Then m="0"&m d=cstr(day(t)) If len(d)=1 Then d="0"&d h=cstr(hour(t)) If len(h)=1 Then h="0"&h mi=cstr(minute(t)) If len(mi)=1 Then mi="0"&mi s=cstr(second(t)) If len(s)=1 Then s="0"&s AliToTime=y&"-"&m&"-"&d&"T"&h&":"&mi&":"&s&"Z" End Function
'简单的使用例子
response.write AliToTime(BeijingtimeToUtc(now())) &"<br>" 2020-04-25T01:14:16Z
response.write AliToTime(UtctoBeijingtime(BeijingtimeToUtc(now()))) &"<br>" 2020-04-25T09:14:16Z
吉公网安备 22020202000301号