1 1 1 1 1 1 1 1 1 1 Rating 3.50 (2 Votes)

Problemstellung:
Umrechnung von UNIX-Timestamp nach Datum und Zeit und umgekehrt.

Voraussetzungen:
Das Bsp ist ab A00 lauffähig.

Funktionsweise:
Es sind 1 API-Funktion und 2 Funktionen erforderlich.

Der Modulkopf sieht so aus:

Public Declare Sub GetSystemTime Lib "kernel32" ( _
    lpSystemTime As SYSTEMTIME)
Public Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type
Public Enum TimeType
    GMT_TIME = 1
    LOCAL_Time = 2
End Enum

1. Errechnen einer Datum- und Zeitangabe aus einem UNIX-Timestamp:

Public Function GetDateTime_UNIX(ByVal dblSec As Double) As Variant
    Dim vResult As Variant
    Dim vStart As Variant
    On Error Resume Next
    vStart = DateSerial(1970, 1, 1)
    vResult = DateAdd("s", dblSec, vStart)
    GetDateTime_UNIX = vResult
    On Error GoTo 0
End Function

2. Errechnen des UNIX-Timestamps aus einer Datum- und Zeitangabe.
     (Wahlweise als GMT-Zeit oder lokaler Zeit)

Public Function GetUnixTime_DATETIME(Optional TM_TYP As TimeType = GMT_TIME) As Long
    Dim nResult As Long
    nResult = DateDiff("s", CDate("01.01.1970 00:00:00"), Now)
    Dim lngDiff As Long
    Dim st As SYSTEMTIME
    If TM_TYP = GMT_TIME Then
        GetSystemTime st
        lngDiff = DateDiff("s", DateSerial(st.wYear, st.wMonth, st.wDay) + _
            TimeSerial(st.wHour, st.wMinute, st.wSecond), Now)
        nResult = nResult - lngDiff
    Else
        nResult = nResult
    End If
    GetUnixTime_DATETIME = nResult
End Function

Wie die Aufrufe erfolgen s. Bsp-DB.

Ergebnis:



Dateien:

Umrechnung von UNIX-Timestamp nach Datum und Zeit und umgekehrt

ab A00

Die Zip-Datei enthält ein Version ab A00
Datum 05.02.2018
Dateigröße 14.45 KB
Download 1.048

Ähnliche Artikel