2010-02-13 17 views

Odpowiedz

14

Jak o:

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

ten nie pozwala na strefach czasowych, UNIX czas jest utc – iKode

+0

Tak, zmieniłem go na ten 'datediff (" s ", # 1970/1/1 #, dateadd ("h", 5, teraz())) '... nie jestem pewny, co zrobię, gdy DST się pojawi. –

+0

Więc nie ma sposobu, aby obsłużyć konwersję do UTC automatycznie? – R01k

1

Oto rozwiązanie: 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 powinien działać szybciej niż roztwór 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 
Powiązane problemy