How Can I Tell if My struct tm Has Been Left in an Invalid State?

后端 未结 2 1779
醉酒成梦
醉酒成梦 2020-12-21 10:49

This is a question about invalid input, not invalid formatting. For example given the following code:

tm bar;

foo >> get_time(&bar, \"%Y-         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-21 11:31

    Since mktime tries to interpret also out-of-range values (i.e. for 2001-02-30 will be interpreted as 2001-03-01), you can do an mktime followed by a localtime, if you get different values back it means that the original ones were not valid.

提交回复
热议问题