Trying to retreive time_t equals to 1 sec. from tm equals Thu Jan 01 00:00:00 1970

63 Views Asked by At

Why is forward conversion from time_t, equaled to 1, to tm valid, whereas backward is not?

#include <ctime>
#include <map>
using namespace std;
int main() {

    time_t timer = 1;
    tm *timerSt = gmtime(&timer);
    cout << asctime(timerSt) << endl;   //Thu Jan 01 00:00:01 1970
    timer = mktime(timerSt);
    cout <<"timer 0: "<< timer << endl; //timer 0: -1
}
0

There are 0 best solutions below