闪击波兰图片:如何用C语言判断日期是否大于2003年6月17日 急急

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/25 08:22:07
如何用C语言判断日期是否大于2003年6月17日

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

#define START_YEAR 1900

void printdate(tm* ltime);

main()
{
tm *mytime;
time_t buf;
buf=time(0);
mytime=(tm*) malloc(sizeof(tm));
mytime=localtime(&buf);
printdate(mytime);
return 0;
}

void printdate(tm* ltime)
{
printf("%d/%d/%d",ltime->tm_mday,ltime->tm_mon+1,ltime->tm_year+START_YEAR);
} //由于月份是0--11,所以转换成实际要+1;年份是从1900年开始算过去了多少年

P.S
tm是一个struct,具体定义如下:
struct tm
{
int tm_sec;// Seconds: 0-59
int tm_min;// Minutes: 0-59
int tm_hour;// Hours since midnight: 0-23
int tm_mday;// Day of the month: 1-31
int tm_mon;// Months *since* January: 0-11
int tm_year;// Years since 1900
int tm_wday;// Days since Sunday (0-6)
int tm_yday;// Days since Jan. 1: 0-365
int tm_isdst;// +1 Daylight Savings Time, 0 No DST
};
结构有了,要和任何一个日期对比就很简单了,只要提取出具体的tm_mon,tm_year,tm_mday就可以对比了。

首先定义一个SYSTEMTIME型变量lt.
包含的头文件为 <windows.h>
然后使用函数 GetLocalTime(<).
此时lt里就含有日期时间信息.
例如: 年: lt.wYear
月: lt.wMonth
日: lt.wDay

然后在程序中进行if判断即可.

简单一点

atol(youdate)>20030601

不过要自己判断合法性