星外飞客

这两个函数分别用于标准时间转Unix时间戳和Unix时间戳转标准时间。用法在函数前面的注释里写得很清楚了。

'参数: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
版权所有,转载请注明出处。
转载自 <a href="http://www.yanghengfei.com/archives/388/" title="在ASP中实现UNIX时间戳的转换" rel="bookmark">在ASP中实现UNIX时间戳的转换 | 星外飞客 </a>

我简单说几句

随机推荐

最新评论

无觅相关文章插件,快速提升流量