ASP沒有像PHP中有函式可以轉換成UNIX時間,所以還得自己寫一個函式來用,
可是本人很懶惰,實在不想自己寫啦!只好請出google大神來幫忙,剛好找到下面這兩個函式:
'參數:strTime:要轉換的時間;intTimeZone:該時間對應的時區
'返回值:strTime相對於1970年1月1日午夜0點經過的秒數
'示例:ToUnixTime("2008-5-23 10:51:0", +8),返回值為1211511060
Function ToUnixTime(strTime, intTimeZone)
If ( IsEmpty(strTime) Or Not IsDate(strTime) ) Then
strTime = Now
End If
If ( IsEmpty(intTimeZone) Or Not isNumeric(intTimeZone) ) Then
intTimeZone = 0
End If
ToUnixTime = DateAdd("h", -intTimeZone, strTime)
ToUnixTime = DateDiff("s","1970-1-1 0:0:0", ToUnixTime)
End Function
'把UNIX時間戳轉換為標準時間
'參數:intTime:要轉換的UNIX時間戳;intTimeZone:該時間戳對應的時區
'返回值:intTime所代表的標準時間
'示例:FromUnixTime("1211511060", +8),返回值2008-5-23 10:51:0
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
End If
FromUnixTime = DateAdd("s", intTime, "1970-1-1 0:0:0")
FromUnixTime = DateAdd("h", intTimeZone, FromUnixTime)
End Function