码迷,mamicode.com
首页 > 系统相关 > 详细

linux判断日期是否合法

时间:2014-09-17 14:52:22      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   div   sp   log   on   

 1 #include <time.h>
 2 #include <stdio.h>
 3  
 4  
 5 typedef enum
 6 {
 7     false = 0,
 8     true = 1
 9 } bool;
10  
11 bool check_date(int year, int month, int day)
12 {
13     if (year < 1900 || month <= 0 || month > 12
14         || day <= 0 || day > 31)
15           return false;
16  
17     struct tm tm_new;
18     tm_new.tm_year = year - 1900;
19     tm_new.tm_mon = month - 1;
20     tm_new.tm_mday = day;
21     tm_new.tm_hour = 0;
22     tm_new.tm_min = 0;
23     tm_new.tm_sec = 0;
24  
25     time_t time_new = mktime(&tm_new);
26     localtime_r(&time_new, &tm_new);
27  
28     if (tm_new.tm_year != year - 1900 || tm_new.tm_mon != month - 1 || tm_new.tm_mday != day)
29           return false;
30     return true;
31 }

 

linux判断日期是否合法

标签:style   blog   color   io   ar   div   sp   log   on   

原文地址:http://www.cnblogs.com/iwateru/p/3976904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!