![]() |
Getting Current UTC - Printable Version +- PowerBASIC Users Meeting Point (http://pump.richheimer.de) +-- Forum: User to User Discussions (http://pump.richheimer.de/forumdisplay.php?fid=3) +--- Forum: PowerBASIC for Windows (http://pump.richheimer.de/forumdisplay.php?fid=4) +--- Thread: Getting Current UTC (/showthread.php?tid=51) Pages:
1
2
|
Getting Current UTC - Owen_English - 05-30-2025 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. RE: Getting Current UTC - Kurt Kuzba - 05-30-2025 Do you mean getting it from the NOWUTC in PowerTime? TimeStringFull? Or how to get it from the web? RE: Getting Current UTC - Owen_English - 05-30-2025 (05-30-2025, 11:32 AM)Kurt Kuzba Wrote: Do you mean getting it from the NOWUTC in PowerTime? TimeStringFull?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! RE: Getting Current UTC - Albert Richheimer - 05-30-2025 (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. You might want to have a look at the PowerTime Object. RE: Getting Current UTC - Owen_English - 05-30-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. RE: Getting Current UTC - Dale Yarker - 05-30-2025 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 RE: Getting Current UTC - George Bleck - 05-30-2025 As simple as a call to GetSystemTime then format the response. But why here instead of PowerBASIC forums? Code: FUNCTION fn_GetCurrentTimeISO8601UTC() AS STRING RE: Getting Current UTC - Stuart McLachlan - 08-31-2025 (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?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 ![]() Code: ' Current Unix Epoch Time (seconds since midnight January 1, 1970 UTC) and ISOTime RE: Getting Current UTC - Eric Pearson - 08-31-2025 > probably better to use (...) the number of seconds (optionally including milliseconds0) since January 1, 1970, at 00:00:00. Horses for courses. I work with data going back to 1960, so I prefer FILETIME: the number of 100-nanosecond units since the start of January 1, 1601. PowerTime is based on FILETIME. But if I was a cosmologist working on the age of the universe, even that would not have enough range, and I wouldn't need nanosecond precision. For the OP's needs, the onlly reason I'd prefer FILETIME is that it is native to the compiler, and Windows uses FILETIME under the hood for everything. RE: Getting Current UTC - Stuart McLachlan - 08-31-2025 (08-31-2025, 08:19 AM)Eric Pearson Wrote: > probably better to use (...) the number of seconds (optionally including milliseconds0) since January 1, 1970, at 00:00:00. Yep, horses for courses. Personally, I like Unix Time for interoperability but there is nothing wrong with Filetime if you need a broader range. But I'd divide it by 10^7 and round as required for ease of use Code: FUNCTION FileTimeStamp(OPT BYVAL decplaces AS LONG) AS STRING Like Google says: Unix time is used in Unix-like operating systems (Linux, macOS, Android), most programming languages (C, Java, Python, JavaScript), and various web platforms and applications for internal timestamps and data exchange. It provides a simple, universal way to represent time as a count of seconds since January 1, 1970, at 00:00:00 Coordinated Universal Time (UTC). Where Unix time is used:
Widely adopted in most modern programming languages for handling dates and times, including Java, Python, JavaScript, C/C++, PHP, and Perl. Web Development: Used for timestamps on web platforms and in data formats like JSON, often in milliseconds rather than seconds. APIs and Data Services: Common in APIs for industrial equipment, such as those using eGauge, BACnet, or Modbus, to report timestamps and time ranges in data. Internal System Timekeeping: Systems use it for internal logging, scheduling tasks, and other functions that require a consistent, universal time representation. Why Unix time is used:
By using UTC as its reference point, it provides a common, time-zone-independent standard across different systems and geographical locations. [*]Interoperability: Its widespread adoption in various systems and languages ensures that data can be shared and understood across different computing environments |