Hey everyone, it seems that ofGetSystemTimeMillis() isn’t working correctly (it seems to be returning a much lower number than it should.
You can test this by using :
auto duration = std::chrono::system_clock::now().time_since_epoch();
uint64_t systemtime = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
ofLogNotice("chrono now().time_since_epoch(): ") << systemtime;
ofLogNotice("ofGetSystemTimeMillis() : ") << ofGetSystemTimeMillis();
On my system at least I get the following :
[notice ] chrono now().time_since_epoch(): : 1670425706801
[notice ] ofGetSystemTimeMillis() : : 9242956
I’ve had a look in the code but unfortunately I’m very confused by std::chrono, otherwise I might be able to help more!
ofGetSystemTimeMillis() reports the time since the system is up. (at least on macOS 12.4!)
Oh interesting… perhaps I misunderstood what it’s supposed to do! In which case… is there an oF way to get the epoch time in Millis?
Not that I’m aware of; I have the equivalence of your chrono code wrapped in an
ofGetUnixTimeMillis() I’m moving around as needed! (I guess it would be a good additions to ofUtils but seeing the platform-specific #ifdef’s in the time-related functions I cannot confirm it works as expected on Windows (it does work on Linux). i assume chrono is cross-plaftorm, but maybe not the same resolution?
Extra information here in case anyone needs it, it seems the the unix epoch time on macOS (and most linux servers) are periodically updated with an NTP server (the interval between checks is adjustable on linux at least).
Every time it does this the time can shift a few seconds so it should not be used to synchronise, say, the start of a show, which is what I’m doing.
I should be better off using system time (which I assume doesn’t get updated using NTP) but as a back up I’ve bought some GPS units from Adafruit and written an Arduino sketch that can send my app the GPS time which should be very accurate across systems.