I wrote a solution for Windows using MSVC2015 where the follow code converts the std::filesystem::last_write_time()
result to time_t
:
time_t ftime = std::file_time_type::clock::to_time_t(fs::last_write_time("/Path/filename"))
It works well. Then, when I tried to port the solution to Linux using gcc 9.3 (-std=C++2a
), I've got the follow error:
Error: 'to_time_t' is not member of 'std::chrono::time_point<std::filesystem::_file_clock>::clock' {aka 'std::filesystem::__file_clock'}
I searched for a solution, but what I found is based on a solution included in an example of std::filesystem::last_write_time()
at cplusplus.com. The solution is shown bellow:
auto ftime = fs::last_write_time(p);
std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime);
Unfortunately, it doesn't work to me. Actually, the example has a comment that says it won't work in MSVC (worked at MSVC2015) or GCC 9; C++20 will allow portable output.
Now, I'm stuck. How can I make this conversion using gcc?