Getting Current UTC
#1
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.
Reply
#2
Do you mean getting it from the NOWUTC in PowerTime? TimeStringFull?
Or how to get it from the web?
Reply
#3
(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!
Reply
#4
(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
Reply
#5
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.
Reply
#6
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
Reply
#7
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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)