📌  相关文章
📜  将 unix 转换为日期 vba 代码示例

📅  最后修改于: 2022-03-11 14:51:57.197000             🧑  作者: Mango

代码示例1
Option Explicit
Const Unix1970 As Double = 25569 'CDbl(DateSerial(1970,1,1)
'' Test in immediate window
'' Print Date2Unix(Timer)
'' Print Unix2Date([paste result from above])

Public Function Date2Unix(ByVal vTimer As Date) As Double
'Always pass value as "Timer" more accurate than "Now" else use a date
    Date2Unix = Split((DateDiff("s", "01/01/1970", Date) + vTimer) * 1000, ".")(0)
End Function

Public Function Unix2Date(vUnixDate As Double) As Date
Dim epochDecimal
    epochDecimal = Left(vUnixDate, 10) & "." & Right(vUnixDate, 3)
    Unix2Date = Format((((epochDecimal / 60) / 60) / 24) + Unix1970, "m/d/yyyy h:nn:ss AM/PM")
End Function