Andrew
Andrew

Reputation: 658

Using the Date.h library how do I convert sys_seconds to time_t type

I'm experimenting with the code provided by @Howard Hinnant in this post which uses his excellent Date.h library. I've renamed the functions to DateTimeToUnix and UnixToDateTime so that it is compatible with my existing code. However, I'm receiving the following error:

E0413   no suitable conversion function from "date::sys_seconds" to "const time_t" exists

on the following code line:

const time_t time_now = lib::DateTimeToUnix(TimeCurrent());

TimeCurrent() is an external function (Pascal) and returns a double TDateTime type.

The question is, how do I convert the output type of sys_seconds to time_t? I noticed that the library chrono has a to_time_t function but I'm not sure how to use it as I've no previous experience of using the chrono features.

I'm using the latest version of VS2019.

Upvotes: 0

Views: 398

Answers (1)

Andrew
Andrew

Reputation: 658

The following code seems to work:

const time_t time_now = std::chrono::system_clock::to_time_t(lib::DateTimeToUnix(TimeCurrent());

Upvotes: 1

Related Questions