Year 2038 - Why does ctime stop at 00:59:59 and not 03:14:07

0

I wrote this program to see what happens after 2038-1-19 03:14:07 by just changing the windows time and printing time with ctime, but to my surprise my program stopped working at 2038-1-19 0:59:59. Why is that so? Is it because of ctime?

This is the code i used:

#include <ctime>
#include <iostream>
#include <windows.h>

int main(void){
    while(true){
        std::time_t t = std::time(0);
        std::tm* now = std::localtime(&t);
        std::cout << (now->tm_year + 1900) << '-'
            << (now->tm_mon + 1) << '-'
            << now->tm_mday << ' '
            << now->tm_hour << ':'
            << now->tm_min << ':'
            << now->tm_sec
            << "\n";
    Sleep(1000);
    }
return 0;
}

And this was the generated output:

...
2038-1-19 0:59:55
2038-1-19 0:59:56
2038-1-19 0:59:57
2038-1-19 0:59:58
2038-1-19 0:59:59

Process returned -1073741819 (0xC0000005)   execution time : 56.917 s
Press any key to continue.
unix-timestamp
ctime
year2038

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0