Date: Thu, 30 Jan 2025 18:08:21 +0100
> On 30 Jan 2025, at 16:14, Enji Cooper (yaneurabeya) via Std-Discussion <std-discussion_at_[hidden]> wrote:
>> So, if you want a time_t value for a utc_clock time_point, you need to first
>> convert that time_point to system_clock and then call to_time_t on the latter.
>> There's clock_cast in [time.clock.cast.fn] to do that. Note: This is non-trivial,
>> because the number of UTC leap seconds that have elapsed at the
>> indicated time point need to be queried from some sort of database.
>
> Got it. This part was honestly difficult to figure out given the sparse documentation on the subject.
I found this to be a good source, including info about epochs for the different clocks:
https://en.cppreference.com/w/cpp/chrono
> I’ll update my demo program based on the insight you provided in your reply.
>
> At the end of the day what I was trying to figure out was how to use the chrono portion of C++11 (and newer) in place of the C/POSIX libcall, `std::gmtime(..)`.
Incidentally, I am doing the same, for a program that computes Julian Day Numbers, and Julian dates, which is useful for converting between calendars such as the Gregorian and Julian calendars, and computing with days and dates. —I could see no support for this in the C++ standard.
>> So, if you want a time_t value for a utc_clock time_point, you need to first
>> convert that time_point to system_clock and then call to_time_t on the latter.
>> There's clock_cast in [time.clock.cast.fn] to do that. Note: This is non-trivial,
>> because the number of UTC leap seconds that have elapsed at the
>> indicated time point need to be queried from some sort of database.
>
> Got it. This part was honestly difficult to figure out given the sparse documentation on the subject.
I found this to be a good source, including info about epochs for the different clocks:
https://en.cppreference.com/w/cpp/chrono
> I’ll update my demo program based on the insight you provided in your reply.
>
> At the end of the day what I was trying to figure out was how to use the chrono portion of C++11 (and newer) in place of the C/POSIX libcall, `std::gmtime(..)`.
Incidentally, I am doing the same, for a program that computes Julian Day Numbers, and Julian dates, which is useful for converting between calendars such as the Gregorian and Julian calendars, and computing with days and dates. —I could see no support for this in the C++ standard.
Received on 2025-01-30 17:08:39