Getting Current UTC
#10
(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.

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.


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
  LOCAL tmpTime AS IPOWERTIME
  LOCAL fmt AS STRING
  fmt = "0"
  IF decplaces > 0 THEN fmt &= "." & STRING$(decplaces,"0")
    tmpTime = CLASS "PowerTime"
    tmptime.NowUTC
    FUNCTION = FORMAT$(tmpTime.Filetime /10^7,fmt)
END FUNCTION


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:
  • Operating Systems:
    Foundational to Unix and Unix-like systems, including Linux, macOS, and mobile operating systems like Android and iOS. 

[*]Programming Languages:
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:
  • Simplicity:
    It's a straightforward way to store and manipulate time as a single integer, making it easy to compare different points in time and perform calculations. 

Universality:
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
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)