GetSystemTimeAsFileTime

Aus API-Wiki
Zur Navigation springenZur Suche springen
Die druckbare Version wird nicht mehr unterstützt und kann Darstellungsfehler aufweisen. Bitte aktualisiere deine Browser-Lesezeichen und verwende stattdessen die Standard-Druckfunktion des Browsers.

Ermittelt die aktuelle Zeit im Format der FILETIME-Struktur.

Deklarationen

<VB> Private Declare Sub GetSystemTimeAsFileTime Lib "kernel32.dll" ( _

                   ByRef lpSystemTimeAsFileTime As FILETIME)

' Alternative Deklaration zur Verwendung mit Variants vom Typ Decimal Private Declare Sub GetSystemTimeAsFileTime Lib "kernel32.dll" ( _

                   ByRef lpSystemTimeAsFileTime As Any)

</VB>

Parameter

lpSystemTimeAsFileTime Variable vom Typ FILETIME, welche die Zahl der vergangenden Zehntel-Mikrosekunden beinhaltet, die seit dem 01.01.1601 vergangen sind

Beispiel

Private Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type

Private Declare Sub GetSystemTimeAsFileTime Lib "kernel32.dll" ( _
                    ByRef lpSystemTimeAsFileTime As FILETIME)

Private Sub Command1_Click()

    Dim FTime As FILETIME
   
    Call GetSystemTimeAsFileTime(FTime)
    Debug.Print "High: " & FTime.dwHighDateTime & " Low: " & FTime.dwLowDateTime

End Sub

Beispiel für Anwendung mit Variant

Private Declare Sub GetSystemTimeAsFileTime Lib "kernel32.dll" ( _
                    ByRef lpSystemTimeAsFileTime As Any)

' Die Deklaration von FILETIME wird hier nicht benötigt
                    
Private Sub Command1_Click()

    Dim FTime As FILETIME
    Dim V As Variant
    Dim C As Double
    Dim Days As Double
    Dim Hours As Long
    Dim Minutes As Long
    Dim Seconds As Long
    Dim Frac As Double
    Dim CurDate As Date
    
    V = CDec(0) ' Variant vorbereiten
    
    Call GetSystemTimeAsFileTime(ByVal (VarPtr(V) + 8))
    
    C = 24# * 60 * 60 * 10000000 ' Anzahl der Zehntel-Mikrosekunden pro Tag
    Days = Int(V / C)
    V = V - Days * C
    
    CurDate = DateAdd("d", Days, CVDate("01.01.1601"))

    C = 60# * 60 * 10000000
    Hours = Int(V / C)
    V = V - Hours * C
     
    C = 60# * 10000000
    Minutes = Int(V / C)
    V = V - Minutes * C
    
    C = 10000000
    Seconds = Int(V / C)
    Frac = V - Seconds * C ' Rest in Einheiten von 100ns
    
    Frac = Frac / 10       ' Rest in µs
    Frac = Frac / 1000     ' Rest in ms
    
    Debug.Print CurDate & " " & TimeSerial(Hours, Minutes, Seconds) & " and " & Frac & " ms"

End Sub

Hinweise

Unter Windows 98 beschränkt sich die Genauigkeit der Zeitangabe auf Millisekunden. Unter XP ist die Zeitauflösung 1µs.

Betriebssystem

Die API-Funktion GetSystemTimeAsFileTime ist unter folgenden Betriebssystemen funktionsfähig:

  • Windows 95 und später.
  • Windows NT 3.1 und später