diego.martinez
diego.martinez

Reputation: 1051

std::localtime returning null

I have an amount of seconds since 1 of january of year 2000. Im trying to build a std::tm structure with it. To do so, I try:

//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 and errno is set to 0, so I don't get what is failing here.

Upvotes: 0

Views: 893

Answers (1)

MannyC
MannyC

Reputation: 46

The value 18446744073709551615 is 2^64 - 1 which is not the number of seconds from 1970 to 2000.

std::time_t is implementation defined, on my machine it is a signed 64 bit integer. Thus, std::time_t time = l; might overflow which might be the reason for std::localtime returning nullptr.

Upvotes: 1

Related Questions