将 sys_seconds 设置为纪元,即零
Set sys_seconds to the epoch i.e. zero
我正在努力寻找将 sys_seconds 重置为零的好方法
date::sys_seconds st;
//st = date::sys_seconds(0); //no matching conversion for functional-style cast from 'int' to 'date::sys_seconds'
//st = date::sys_seconds{date::sys_seconds(0)}; //no matching conversion for functional-style cast from 'int' to 'date::sys_seconds'
//st = std::chrono::system_clock::from_time_t(0); //no viable overloaded '='
//st = date::sys_seconds(std::chrono::system_clock::from_time_t(0)); //no matching conversion for functional-style cast
st = std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::from_time_t(0)); //works, but verbose
有没有更好的方法?
st = {};
说明:sys_seconds
的默认构造函数将事物设置为零。所以这只是默认构造一个sys_seconds
并将其赋值给st
。其他方法包括:
st = date::sys_seconds{};
和:
using namespace std::chrono_literals;
st = date::sys_seconds{0s};
我正在努力寻找将 sys_seconds 重置为零的好方法
date::sys_seconds st;
//st = date::sys_seconds(0); //no matching conversion for functional-style cast from 'int' to 'date::sys_seconds'
//st = date::sys_seconds{date::sys_seconds(0)}; //no matching conversion for functional-style cast from 'int' to 'date::sys_seconds'
//st = std::chrono::system_clock::from_time_t(0); //no viable overloaded '='
//st = date::sys_seconds(std::chrono::system_clock::from_time_t(0)); //no matching conversion for functional-style cast
st = std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::from_time_t(0)); //works, but verbose
有没有更好的方法?
st = {};
说明:sys_seconds
的默认构造函数将事物设置为零。所以这只是默认构造一个sys_seconds
并将其赋值给st
。其他方法包括:
st = date::sys_seconds{};
和:
using namespace std::chrono_literals;
st = date::sys_seconds{0s};