Date: Wed, 29 Jan 2025 19:40:17 -0800
Hi all,
I tried writing up a simple example for how to calculate the time in Unix epoch using std::time_t, and was a bit confused when I found out that there doesn’t seem to be a clean way to convert from `std::chrono::utc_clock::now()` to a `std::time_t` quantity, unlike `std::chrono::system_clock::to_time_t(..)`. Can someone help me understand if I need to convert to time_t using `std::chrono::system_clock`, and/or confirm that the standard library lacks a clear way to convert to/from `std::time_t` using `std::chrono::unix_clock`.
I tried using g++ 13.13.0 and clang++ 19.1.6. libc++ (clang) seems to extend `std::chrono::utc_clock` directly from `std::chrono::system_clock` (but fails when converting UTC timepoints), whereas libstdc++ (gcc) provides a non-derivative implementation of `std::chrono::utc_clock` (which doesn’t provide a `to_time_t(..)` conversion interface).
Thanks!
-Enji
I tried writing up a simple example for how to calculate the time in Unix epoch using std::time_t, and was a bit confused when I found out that there doesn’t seem to be a clean way to convert from `std::chrono::utc_clock::now()` to a `std::time_t` quantity, unlike `std::chrono::system_clock::to_time_t(..)`. Can someone help me understand if I need to convert to time_t using `std::chrono::system_clock`, and/or confirm that the standard library lacks a clear way to convert to/from `std::time_t` using `std::chrono::unix_clock`.
I tried using g++ 13.13.0 and clang++ 19.1.6. libc++ (clang) seems to extend `std::chrono::utc_clock` directly from `std::chrono::system_clock` (but fails when converting UTC timepoints), whereas libstdc++ (gcc) provides a non-derivative implementation of `std::chrono::utc_clock` (which doesn’t provide a `to_time_t(..)` conversion interface).
Thanks!
-Enji
Received on 2025-01-30 03:40:33