difftime 返回错误的数字

difftime is returning a wrong number

#include <iostream>
#include <ctime>
using namespace std;

int main()
{
    double seconds;    
    struct tm birth = {0}; //10-28-1955
    birth.tm_year = 55;
    birth.tm_mon = 9;
    birth.tm_mday = 28;
    birth.tm_sec = 0;

    struct tm present = {0}; //2-10-2021 
    present.tm_year = 121;
    present.tm_mon = 1;
    present.tm_mday = 10;
    present.tm_sec = 0;

    time_t p1 = mktime(&present);
    time_t b1 = mktime(&birth);
    seconds = (difftime(p1, b1));
    seconds /= 86400;
    cout << "Bill "
         << "Gates- " << seconds << "days" << endl;
}

输出:

Bill Gates- 18668.2days

我正在尝试使用 <ctime> 来尝试找出比尔·盖茨在 2-10-2021 之前活着的天数。我得到 18668.2 的答案;那还差得远,因为实际上应该是 20000 天左右。

调试时,一切正常,直到第 21 行。

到第22行时,b1变为-1。

我不确定如何解决这个问题。我为 struct birth 输入的日期似乎没问题。

When it reaches line 22, b1 becomes -1.

抱歉,您的 C 标准库不足以处理您的日期。使用(或编写)一个不同的库来表示 1970 年之前的时间。

同时,您正在使用 C++ - 无需使用 C 函数。尝试使用作为 C++ 标准库的一部分的 chrono library