Hier habe ich einige Funktionen für das Handling mit Unix-Timestamps unter LotusScript erstellt.
Die Funktionen ermöglichen aus einem Datums-Objekt einen Timestamp zu erzeugen und auch den Timestamp wieder zurück zu konvertieren.

Konvertierung Timestamp zu NotesDateTime Objekt

Public Function getDateTime(timestamp As Long) As NotesDateTime
         Const EPOCH_DATE = "01/01/1970 00:00:00"
         Const SECONDS_DAY = 86400
         Const SECONDS_HOUR = 3600

         Dim adjDays As Integer
         Dim adjSeconds As Double
         Dim adjHours As Integer
         Dim epochDate As New NotesDateTime(EPOCH_DATE)

         adjDays = Fix(timestamp/SECONDS_DAY)
         adjSeconds = timestamp Mod SECONDS_DAY
         adjHours = Fix(adjSeconds/SECONDS_HOUR)
         adjSeconds = adjSeconds Mod SECONDS_HOUR 'Adjust minutes and extra seconds

         Call epochDate.AdjustDay(adjDays)
         Call epochDate.AdjustHour(adjHours)
         Call epochDate.AdjustSecond(adjSeconds)

         Set getDateTime = epochDate
End Function

Konvertierung Timestamp zu String Objekt

Public Function getDateTimeString(timestamp As Long) As String
         Const EPOCH_DATE = "01/01/1970 00:00:00"
         Const RETURN_FORMAT = "dd/mm/yyyy hh:mm:ss"
         Const SECONDS_DAY = 86400
         Const SECONDS_HOUR = 3600

         Dim adjDays As Integer
         Dim adjSeconds As Double
         Dim adjHours As Integer
         Dim epochDate As New NotesDateTime(EPOCH_DATE)

         adjDays = Fix(timestamp/SECONDS_DAY)
         adjSeconds = timestamp Mod SECONDS_DAY
         adjHours = Fix(adjSeconds/SECONDS_HOUR)
         adjSeconds = adjSeconds Mod SECONDS_HOUR 'Adjust minutes and extra seconds

         Call epochDate.AdjustDay(adjDays)
         Call epochDate.AdjustHour(adjHours)
         Call epochDate.AdjustSecond(adjSeconds)

         getDateTimeString = Format(epochDate.LSLocalTime, RETURN_FORMAT)
End Function

Konvertierung Datum zu Timestamp

Function getTimestamp(dt As Variant) As Long
         Const EPOCH_DATE = "01/01/1970 00:00:00"
         Const DT_TYPENAME= "NOTESDATETIME"

        Dim epochDT As New NotesDateTime(EPOCH_DATE)
        Dim tempDT As New NotesDateTime(Now)
        If(TypeName(dt) = DT_TYPENAME) Then
                  tempDT.LSLocalTime = dt.Lslocaltime
        Else
                 tempDT.LSLocalTime = dt
         End If
        getTimestamp = tempDT.TimeDifference(epochDT)
End Function

Beispiel wie die Funktionen aufgerufen werden:

Dim dt As New NotesDateTime(Now)
Dim msg As String
Dim stamp As Long

stamp = getTimestamp(dt)
stamp = getTimestamp(dt.Lslocaltime)

msg = "StampDT: " & stamp & Chr(10) & Chr(13)
msg =  msg & "StampLt: " & stamp & Chr(10) & Chr(13)
msg = msg & "DTStr: " & getDateTimeString(stamp) & Chr(10) & Chr(13)
msg = msg & "DT: " & getDateTime(stamp).Localtime & Chr(10) & Chr(13)
MessageBox msg
Snippet: Arbeiten mit Unix Timestamps – Konvertierung DateTime zu Timestamp und zurück
Markiert in:     

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert