Posts: 4
Threads: 1
Joined: May 2025
05-30-2025, 06:22 AM
(This post was last modified: 05-30-2025, 06:28 AM by Owen_English.)
Have waded back thru the previous forum posts but at a loss to get an answer.
Sorry if it's been asked before but all I need is the numerical string for the Current UTC timestamp.
How?
Thanks.
Posts: 1
Threads: 0
Joined: Feb 2025
Do you mean getting it from the NOWUTC in PowerTime? TimeStringFull?
Or how to get it from the web?
Posts: 4
Threads: 1
Joined: May 2025
05-30-2025, 11:45 AM
(This post was last modified: 05-30-2025, 11:48 AM by Owen_English.)
(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!
Posts: 60
Threads: 7
Joined: May 2024
05-30-2025, 11:54 AM
(This post was last modified: 05-30-2025, 11:56 AM by Albert Richheimer.)
(05-30-2025, 06:22 AM)Owen_English Wrote: Sorry if it's been asked before but all I need is the numerical string for the Current UTC timestamp.
How?
You might want to have a look at the
PowerTime Object.
„Let the machine do the dirty work.“
The Elements of Programming Style, Brian W. Kernighan, P. J. Plauger 1978
Posts: 4
Threads: 1
Joined: May 2025
Yes, am looking at that, seems as tho needs 20-30 lines of code to get the UTC 'now' string and just wondered if there was a simpler way of doing it.
Posts: 20
Threads: 4
Joined: May 2024
05-30-2025, 12:09 PM
(This post was last modified: 05-30-2025, 12:26 PM by Dale Yarker.)
Do you have PBWin 10.0x for PowerTime?
" Just need the UTC as a string to log events against and to keep a note of elapsed time." To do arithmetic in time (like elapsed) get/keep the stamp in PowerTime (AKA QUAD or FileTime), then convert to text number for display or print.
For older PB versions the API functions are not hard to do.
Cheers,
we cross posted on last.
30 lines? Where is that?
Looks closer to 4 lines at a quick glance:
NOW
TIMEDIFF
DATESTRING
TIMESTRINGFULL
Posts: 8
Threads: 1
Joined: May 2024
05-30-2025, 10:29 PM
(This post was last modified: 05-30-2025, 10:35 PM by George Bleck.)
As simple as a call to GetSystemTime then format the response. But why here instead of PowerBASIC forums?
Code:
FUNCTION fn_GetCurrentTimeISO8601UTC() AS STRING
LOCAL v_udtST AS SYSTEMTIME
LOCAL v_strTimpstamp AS STRING
GETSYSTEMTIME v_udtST
FUNCTION = fn_SystemTimeToISO8601(v_udtST)
END FUNCTION
'----------------------------------------------------------------------------(')
FUNCTION fn_SystemTimeToISO8601(BYREF v_udtST AS SYSTEMTIME) AS STRING
FUNCTION = _
FORMAT$(v_udtST.wYear, "0000") & _
FORMAT$(v_udtST.wMonth, "00") & _
FORMAT$(v_udtST.wDay, "00") & _
"T" & _ _
FORMAT$(v_udtST.wHour, "00") & _
FORMAT$(v_udtST.wMinute, "00") & _
FORMAT$(v_udtST.wSecond, "00") & _
"Z"
END FUNCTION