2010-02-13 102 views

回答

14

如何:

datediff("s",#1970/1/1#,now()) 
+2

這不允許時區,UNIX時間是utc – iKode 2015-04-09 18:44:05

+0

是的,我將它改爲這個'datediff(「s」,#1970/1/1#,dateadd(「h」,5,now()))'......不知道當DST轉身時我該怎麼辦。 – 2016-08-15 19:39:50

+0

因此無法自動處理到UTC的轉換? – R01k 2018-02-14 23:58:44

1

這裏有一個解決方案:http://vbcity.com/forums/t/5084.aspx

Function UnixTime() As Variant 
    'The first parameter determines how the 
    ' difference will be measured in i.e. "S" for seconds 
    UnixTime = DateDiff("S", "1/1/1970", Now()) 
End Function 
9

This應該跑得比DateDiff的解決方案快:

Private Function Long2Date(lngDate As Long) As Date 
    Long2Date = lngDate/86400# + #1/1/1970# 
End Function 

Private Function Date2Long(dtmDate As Date) As Long 
    Date2Long = (dtmDate - #1/1/1970#) * 86400 
End Function 
相關問題