C++ C++;20 VS2019中的计时解析问题(最新版本)

C++ C++;20 VS2019中的计时解析问题(最新版本),c++,date,c++20,chrono,C++,Date,C++20,Chrono,我有一个使用date.h库在C++14下工作的函数,但我正在将我的程序转换为使用C++20,它不再工作了。请问我做错了什么 我的C++14/date.h代码如下: #include <date/date.h> // latest, installed via vcpkg #include <chrono> auto StringToUnix(const std::string& source) -> std::time_t { auto in =

我有一个使用date.h库在C++14下工作的函数,但我正在将我的程序转换为使用C++20,它不再工作了。请问我做错了什么

我的C++14/date.h代码如下:

#include <date/date.h> // latest, installed via vcpkg
#include <chrono>

auto StringToUnix(const std::string& source) -> std::time_t
{
    auto in = std::istringstream(source);
    auto tp = date::sys_seconds{};
    in >> date::parse("%Y-%m-%d %H:%M:%S", tp); 

    return std::chrono::system_clock::to_time_t(tp);
}
#include <chrono>

auto StringToUnix(const std::string& source) -> std::time_t
{
    using namespace std::chrono;
    auto in = std::istringstream(source);
    auto tp = sys_seconds{};
    in >> parse("%Y-%m-%d %H:%M:%S", tp);

    return system_clock::to_time_t(tp);
}

有没有任何细微的变化,我错过了?请问是什么原因导致此错误?

规范中有一个错误正在修复中。VS2019忠实地复制了规范。将格式字符串包装在
string{}
中,或者给它一个尾随
s
文本,将其转换为字符串,这将解决该错误

in >> parse("%Y-%m-%d %H:%M:%S"s, tp);

您的编译器是否支持新的日期功能?检查编译器的文档,看看它支持多少C++20,因为还没有编译器提供100%的支持。
in >> parse("%Y-%m-%d %H:%M:%S"s, tp);