My operating system, Windows, keeps track of the time and date, it's at the bottom right corner of the desktop. If I want to get the time and date, I'd expect a call (maybe a system call) that retrieves those values written at the bottom right of my screen. Instead the way people tell you to get the system time is by using functions and types such at std::chrono::clock::now
and the C type time_t
which are just a single (or maybe more) integer. Then there's another step. Usually this is demonstrated with logging that type, for example:
auto start = std::chrono::system_clock::now();auto legacyStart = std::chrono::system_clock::to_time_t(start);std::cout << std::ctime(&legacyStart) << '\n';
The conversion I'm guessing involves something like Zeller's Algorithm to calculate the day of the week from a certain time point.
My question is, is there a more efficient way to just read the system time from your operating system?
Also, on a related note, is this how the operating system does it? Keeps time by adding whatever time has passed to an integer (possibly the number of seconds since POSIX time), and then does a conversion every time to display that date and time?