VBA 获得Excel时间戳
Function getTimestamp(t2 As Date) As Long
Dim t As Long, t1 As Date
t1 = “1970-1-1 8:00” '北京时区 东八区
t = (t2 - t1) * 86400 '转换为秒
getTimestamp = t
End Function
Sub test() '演示如何获得 时间戳
'd = getTimestamp(Now) '获取当前时间戳
d = getTimestamp(“1970-1-1 8:00”) '获取指定日期的时间戳
MsgBox d
End Sub
VBA 定义的函数,可以在Excel编辑时,用调用Excel一样的方式 调用