首页 /编程语言和算法/VB6/VBA/ASP
 VBA代码 Unix时间戳
2025年3月18日 14:59
Function ToUnixTime(strTime, intTimeZone)
    '参数:strTime:要转换的时间;intTimeZone:该时间对应的时区
    '返回值:strTime相对于1970年1月1日午夜0点经过的秒数
    '示例:ToUnixTime("2008-5-23 10:51:0", +8),返回值为1211511060
    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


 
全部回复(0)
首页 | 电脑版 |