C : Validation in strptime
问题 strptime() function in C fails to detect invalid dates. Ex: 2011-02-31 , 2011-04-31. Is there any other function or workaround to this problem 回答1: You can use mktime to normalize your structure after using strptime . struct tm ltm = {0}; char buf[] = "2011-02-31"; puts(buf); strptime(buf, "%Y-%m-%d", <m); mktime(<m); strftime(buf, sizeof(buf), "%Y-%m-%d", <m); puts(buf); The example above will produce the output below: 2011-02-31 2011-03-03 If the strings before and after mktime do not