Question

I saw this in the mktime cppreference:

Time since epoch as a std::time_t object on success or -1 if time cannot be represented as a std::time_t object.

And I started wondering when would this happen. Could anyone give an example where mktime returned -1?

Was it helpful?

Solution

The time_t can only represent a finite interval, at least on any system I've seen. If the date you request is outside that interval (say tm_year equal to 250 on a Unix machine with a 32 bit time_t), then mktime will return -1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top