asp实现时间戳函数asp

/ / 2016-07-24   阅读:2498
<% '========================================================= '把标准时间转换为UNIX时间戳 '参数:strTime:要转换的时间;intTimeZone:该时间对应的时区 '返回值:strTime相对于1970年1月1日午夜0点经...
<%
'=========================================================
'把标准时间转换为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
%>

我要评论

昵称:
验证码:

最新评论

共0条 共0页 10条/页 首页 上一页 下一页 尾页
意见反馈