UNIX時間轉換ASP代碼.txt

'參數: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
If IsEmpty(intTimeZone) or Not isNumeric(intTimeZone) Then intTimeZone = 0
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
FromUnixTime = DateAdd("s", intTime, "1970-1-1 0:0:0")
FromUnixTime = DateAdd("h", intTimeZone, FromUnixTime)
End Function it

相關文章
相關標籤/搜索