I want to send a time point over a network connection to detect the ping time and for other calculations. The time has to have millisecond precision, but using:
auto currently = std::chrono::time_point_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now()
);
... returns (of course) the system time which is of course not UTC. Is there any way to calculate the UTC value without transforming the time_point to a time_t and then back again? I read something about std::chrono::utc_clock, but even with C++20 I can not find the definition in the <chrono> header.
Edit
This would be a working solution, but it is an awful solution, because it is very inefficient... There must be something better:
auto currently = std::chrono::time_point_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now()
);
time_t time = std::chrono::system_clock::to_time_t(currently);
struct tm *tm = gmtime(&time);
// Create a new time_point from struct tm that is in UTC now