linux判断日期是否合法

时间:2021-07-30 09:04:13
 #include <time.h>
#include <stdio.h> typedef enum
{
false = ,
true =
} bool; bool check_date(int year, int month, int day)
{
if (year < || month <= || month >
|| day <= || day > )
return false; struct tm tm_new;
tm_new.tm_year = year - ;
tm_new.tm_mon = month - ;
tm_new.tm_mday = day;
tm_new.tm_hour = ;
tm_new.tm_min = ;
tm_new.tm_sec = ; time_t time_new = mktime(&tm_new);
localtime_r(&time_new, &tm_new); if (tm_new.tm_year != year - || tm_new.tm_mon != month - || tm_new.tm_mday != day)
return false;
return true;
}