本帖最后由 pcl_test 于 2016-6-28 09:07 编辑
- Function ToUnixTime(dt, ms, n)
- Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
- Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
- For Each objItem in colItems
- TimeZone = objItem.CurrentTimeZone
- If isNull(ms)=true Then
- ms = left(split(objItem.LocalDateTime, ".")(1), 3)
- End If
- Next
- ToUnixTime = DateDiff("s", "1970-1-1 0:0:0", dt) - TimeZone*60
- If n=1 Then ToUnixTime = ToUnixTime *1000 + ms
- End Function
- 'msgbox ToUnixTime(CDate("2010/03/08 10:01:02"), 000, 1)
- msgbox ToUnixTime(now(), null, 1) '0表示输出秒级Unix时间戳,1表示输出毫秒级
复制代码
- Function FromUnixTime(ts, n)
- Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
- Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
- For Each objItem in colItems
- TimeZone = objItem.CurrentTimeZone
- Next
- ms = ""
- If n = 1 Then
- 'ms = "." & right(ts, 3)
- ts = left(ts, len(ts) -3)
- End If
- FromUnixTime = DateAdd("s", ts + TimeZone*60, "1970-1-1 0:0:0") & ms
- End Function
- msgbox FromUnixTime(1293072805000, 1) '0表示以秒级转换成时间,1表示以毫秒级转换
复制代码
|