std::localtime 返回 null
std::localtime returning null
我有自 2000 年 1 月 1 日以来的秒数。
我正在尝试用它构建一个 std::tm 结构。
为此,我尝试:
//seconds from 1970 to 2000.
unsigned long long secstoposix = 946684800;
//secsfromdate is the amount of secs since 2000...
unsigned long long l=secstoposix + secsfromdate;
this->time=l; //(posix+amount)
tm=*std::localtime(&time); // <-- std::localtime returns null.
localtime returns null 并且 errno 设置为 0,所以我不明白这里发生了什么。
值 18446744073709551615
是 2^64 - 1
这不是从 1970 到 2000 的秒数。
std::time_t
是实现定义的,在我的机器上它是一个带符号的 64 位整数。因此,std::time_t time = l;
可能溢出,这可能是 std::localtime
返回 nullptr
的原因。
我有自 2000 年 1 月 1 日以来的秒数。 我正在尝试用它构建一个 std::tm 结构。 为此,我尝试:
//seconds from 1970 to 2000.
unsigned long long secstoposix = 946684800;
//secsfromdate is the amount of secs since 2000...
unsigned long long l=secstoposix + secsfromdate;
this->time=l; //(posix+amount)
tm=*std::localtime(&time); // <-- std::localtime returns null.
localtime returns null 并且 errno 设置为 0,所以我不明白这里发生了什么。
值 18446744073709551615
是 2^64 - 1
这不是从 1970 到 2000 的秒数。
std::time_t
是实现定义的,在我的机器上它是一个带符号的 64 位整数。因此,std::time_t time = l;
可能溢出,这可能是 std::localtime
返回 nullptr
的原因。