Getting Current UTC
#8
(05-30-2025, 11:45 AM)Owen_English Wrote:
(05-30-2025, 11:32 AM)Kurt Kuzba Wrote: Do you mean getting it from the NOWUTC in PowerTime? TimeStringFull?
Or how to get it from the web?
Thanks Kurt, not web.  Just need the UTC as a string to log events against and to keep a note of elapsed time. Trying to keep it simple!

Resurrecting this thread after browsing the forum.

To keep track of elapsed time it is probably better to use what is commonly called a Posix/Unix/Epoch Timestamp (as a string if necessary). That allow easy log sorting and elapsed time calculations . It is the number of seconds (optionally including milliseconds0) since  January 1, 1970, at 00:00:00.
Compare to doing arithmetic on an ISO DateTime string Sad'
Code:
' Current Unix Epoch Time (seconds since midnight January 1, 1970 UTC) and ISOTime
#COMPILE EXE
#DIM ALL
FUNCTION PBMAIN () AS LONG
    ? STR$(UnixTimeStamp) & $LF & STR$(UnixTimeStampD) & $LF & ISODateTime & $LF & ISODateTimeD
END FUNCTION

FUNCTION UnixTimeStamp() AS LONG ' Integer stamp
    LOCAL tmpTime AS IPOWERTIME
    tmpTime = CLASS "PowerTime"
    tmptime.nowUtc
    FUNCTION = tmpTime.filetime/10000000 - 11644473600
END FUNCTION

FUNCTION UnixTimeStampD AS DOUBLE ' With milliseconds
    LOCAL NowTime AS IPOWERTIME
    NowTime = CLASS "PowerTime"
    NowTime.NowUTC ' get current Time in UTC
    FUNCTION = NowTime.FileTime /10000000 - 11644473600
END FUNCTION

FUNCTION ISODateTime() AS STRING 'To second
  LOCAL tmpTime AS IPOWERTIME
    tmpTime = CLASS "PowerTime"
    tmptime.NowUTC
    FUNCTION = CHR$(FORMAT$(tmpTime.Year,"0000"),FORMAT$(tmpTime.Month,"00"),FORMAT$(tmpTime.Day,"00"),"T", _
              FORMAT$(tmpTime.Hour,"00"),FORMAT$(tmpTime.Minute,"00"),FORMAT$(tmpTime.Second,"00"))
END FUNCTION
FUNCTION ISODateTimeD() AS STRING 'Decimal - incl msecs
  LOCAL tmpTime AS IPOWERTIME
    tmpTime = CLASS "PowerTime"
    tmptime.NowUTC
    FUNCTION = CHR$(FORMAT$(tmpTime.Year,"0000"),FORMAT$(tmpTime.Month,"00"),FORMAT$(tmpTime.Day,"00"),"T", _         FORMAT$(tmpTime.Hour,"00"),FORMAT$(tmpTime.Minute,"00"),FORMAT$(tmpTime.Second,"00"),".",FORMAT$(tmpTime.mSecond,"000"))
END FUNCTION
'
Reply


Messages In This Thread
Getting Current UTC - by Owen_English - 05-30-2025, 06:22 AM
RE: Getting Current UTC - by Kurt Kuzba - 05-30-2025, 11:32 AM
RE: Getting Current UTC - by Owen_English - 05-30-2025, 11:45 AM
RE: Getting Current UTC - by Stuart McLachlan - 08-31-2025, 03:06 AM
RE: Getting Current UTC - by Albert Richheimer - 05-30-2025, 11:54 AM
RE: Getting Current UTC - by Owen_English - 05-30-2025, 11:58 AM
RE: Getting Current UTC - by Dale Yarker - 05-30-2025, 12:09 PM
RE: Getting Current UTC - by George Bleck - 05-30-2025, 10:29 PM
RE: Getting Current UTC - by Eric Pearson - 08-31-2025, 08:19 AM
RE: Getting Current UTC - by Stuart McLachlan - 08-31-2025, 09:04 AM
RE: Getting Current UTC - by Stuart McLachlan - 09-01-2025, 06:06 AM
RE: Getting Current UTC - by Dale Yarker - 09-01-2025, 08:06 AM
RE: Getting Current UTC - by Dale Yarker - 09-01-2025, 10:02 AM
RE: Getting Current UTC - by Stuart McLachlan - 09-01-2025, 10:37 AM
RE: Getting Current UTC - by Stuart McLachlan - 09-03-2025, 06:05 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)