The high_resolution_clock::now().time_since_epoch() returns significantly different results on Windows and Linux.
On Linux it returns the duration from 1.1.1970 to now.
On Windows it returns the duration of 21 days only.
I was running the following simple code on Windows
#include<iostream>
#include<chrono>
int main(int argc, char** argv)
{
std::cout << std::chrono::high_resolution_clock::now().time_since_epoch().count() << std::endl;
return 0;
}
and the result was 1819149491213100 ns, which was just 21 days.
I then ran the code on Linux and it printed the time since 1.1.1970 (which is what I expected).
I also tired the steady_clock, and the results were similar. But when I try system_clock, the behaviour on both OSs turn out to be consistent.
Why does this code behave so differently on different OSs?
The results indicate that Windows and Linux use different epoch times, but where does this 21 days come from?
Does this various behaviour indicate that we should not use high_resolution_clock for timestamps, but for computing durations only?
ps: I ran the code on Visual Studio 2022.