How to control the displayed precision when sending `std::chrono::locale_time` to a c++ stream?

Advertisements I’m almost happy with this: const auto time = std::chrono::current_zone()->to_local(std::chrono::system_clock::now()); std::cout << time; It prints: 2023-07-26 21:08:47.2889025 that’s great, but I’d like it to print slightly less decimals, for instance: 2023-07-26 21:08:47.289 Is there some iomanip-like ways of specifying the desired precision? Something like: std::cout << std::chrono::setprecision(3) << time; >Solution : Just floor it… Read More How to control the displayed precision when sending `std::chrono::locale_time` to a c++ stream?

Why are my time conversions inconsistent?

Advertisements Quick background: my application accesses multiple data sources that report timestamped data, each timestamp is reported as Unix epoch seconds, e.g. data reports 1656331210. The user can input a requested time to report as an ISO date string, such as 2022-06-27T12:00:10Z. These two values are considered equivalent. My problem is consistently converting back and… Read More Why are my time conversions inconsistent?

Why does the runtime of high_resolution_clock increase with the greater frequency I call it?

Advertisements In the following code, I repeatedly call std::chrono::high_resolution_clock::now twice, and measure the time it took between these two calls. I would expect this time to be very small, since there is no other code is run between these two calls. However, I observe strange behavior. For small N, the max element is within a… Read More Why does the runtime of high_resolution_clock increase with the greater frequency I call it?