eine verbesserte Version, mit TimeZone, liefert nun Andreas Gehrs-Pahl
Code: Alles auswählen
#include "OT4XB.CH"
Procedure Main()
LOCAL cDate1 := '2018-10-27'
LOCAL cDate2 := '2018-10-30'
LOCAL cTime1 := '23:59:00'
LOCAL cTime2 := '23:59:01'
LOCAL cOffset1 := '+02:00' // CEST ==> +02:00
LOCAL cOffset2 := '+01:00' // CET ==> +01:00
LOCAL cPrefix := 'Difference is: '
LOCAL nOneDay := 86400 // 60 * 60 * 24
LOCAL nMinutes1 := 0 // CEST ==> 120
LOCAL nMinutes2 := 0 // CET ==> 60
LOCAL nSeconds := 0
LOCAL nDays := 0
LOCAL oFT1 := FileTime64():New()
LOCAL oFT2 := FileTime64():New()
oFT1:SetTimeStamp(cDate1 + 'T' + cTime1 + cOffset1, @nMinutes1)
QOut('Local Date Time: ' + oFT1:GetTimeStamp())
QOut('Time Zone Offset: ' + alltrim(str(nMinutes1)) + ' Minutes')
oFT1:AddMinutes(0 - nMinutes1)
QOut('UTC as Date Time: ' + DtoC(oFT1:dDate) + ' ' + oFT1:cTime)
QOut('UTC as TimeStamp: ' + oFT1:GetTimeStamp())
QOut('UTC for RFC 822: ' + oFT1:ToHTTP())
QOut('')
oFT2:SetTimeStamp(cDate2 + 'T' + cTime2 + cOffset2, @nMinutes2)
QOut('Local Date Time: ' + oFT2:GetTimeStamp())
QOut('Time Zone Offset: ' + alltrim(str(nMinutes2)) + ' Minutes')
oFT2:AddMinutes(0 - nMinutes2)
QOut('UTC as Date Time: ' + DtoC(oFT2:dDate) + ' ' + oFT2:cTime)
QOut('UTC as TimeStamp: ' + oFT2:GetTimeStamp())
QOut('UTC for RFC 822: ' + oFT2:ToHTTP())
QOut('')
nSeconds := ft64_ElapSeconds(oFT1, oFT2)
if nSeconds < 0
cPrefix += 'Negative '
nSeconds := abs(nSeconds)
endif
QOut(cPrefix)
if nSeconds > nOneDay
nDays := int(nSeconds / nOneDay)
nSeconds -= nDays * nOneDay
endif
if nDays > 0
QQOut(alltrim(str(nDays)) + " Day" + iif(nDays == 1, " ", "s "))
endif
QQOut(Seconds_to_Time(nSeconds))
return
Function Seconds_to_Time(nSeconds)
LOCAL nHours := int(nSeconds / 3600)
LOCAL nMinutes := int((nSeconds - (nHours * 3600)) / 60)
LOCAL nRest := nSeconds - (nHours * 3600 + nMinutes * 60)
LOCAL lDecimals := nSeconds > int(nSeconds)
return (StrZero(nHours, 2) + ':' + StrZero(nMinutes, 2) + ':' + ;
StrZero(int(nRest), 2) + iif(lDecimals, '.' + StrZero(100 * (nSeconds - ;
int(nSeconds)), 2), ''))
^
---
da ich nur die "absolute" Zeit haben will kann ich auch die API Funktion "GetTickCount" verwenden
Code: Alles auswählen
FUNCTION SystemUpTime()
RETURN DllCall("Kernel32.dll",DLL_STDCALL,"GetTickCount")
damit erhalte ich die "Ticks" wie lange der PC schon läuft.