I've got a string representing a date in the format <year>.<day-of-the-year>.<hours>.<minutes>.<seconds>
.
Example: 2021.147.17.33.45
is the 27th of May 2021, with time 17:33:45.
How to parse this formatted time string into a std::chrono::system_clock::time_point
using Howard Hinnant's date library or the equivalent C++20 functionalities?
I've tried with the following, with no result: the output time_point
is always zero.
auto toTimePoint(const std::string& val)
{
std::istringstream ss(val);
std::chrono::system_clock::time_point tp;
std::chrono::from_stream(ss, "%Y.%j.%H.%M.%S", tp)
return tp;
}
EDIT: This code fails using Visual Studio v16.10 with \std:c++latest
, but works correctly using Howard Hinnant's date library (see the comment of T.C. below). I've opened a new issue on the Microsoft STL GitHub repository.