gpt4 book ai didi

c++ - localtime_r对于大数返回null

转载 作者:行者123 更新时间:2023-12-02 09:47:37 25 4
gpt4 key购买 nike

  • 我的秒数很大。我想将秒数转换为struct tm,但是当我使用localtime_r时,它会返回null。
  • 有什么方法可以将较大的秒数转换为struct tm

  • 要么
  • 我可以传递给localtime_r函数以使其不返回NULL的最大值是多少?
  • #include <bits/stdc++.h>
    #include <map>
    #include <time.h>
    using namespace std;
    int main ()
    {
    time_t seconds= 9223372036854775807;
    struct tm timeResult;
    struct tm *endTimeTm = localtime_r(&seconds, &timeResult);
    if (!endTimeTm)cout<<"null";
    else cout<<"not null";
    return 0;
    }

    最佳答案

    is there any way to convert large value of seconds into struct tm


    即使使用64位 time_t,9223372036854775807当然也超出了 localtime_r()可以转换的范围。 .tm_year成员的值太大-超出 int范围。

    关于c++ - localtime_r对于大数返回null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64260036/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com