#include <time.h> #include <stdio.h> int CheckTime( char *date1, char *date2) { struct tm st,stt; time_t mkst,mkstt; int yb,mb,db; int b; double lt; sscanf(date1, "%4d%02d%02d%02d%02d%02d", &st.tm_year, &st.tm_mon, &st.tm_mday, &st.tm_hour, &st.tm_min, &st.tm_sec ); sscanf(date2, "%4d%02d%02d%02d%02d%02d", &stt.tm_year, &stt.tm_mon, &stt.tm_mday, &stt.tm_hour, &stt.tm_min, &stt.tm_sec ); st.tm_year -= 1900; stt.tm_year -= 1900; printf("%d\n",stt.tm_year); printf("%d\n",stt.tm_mon); printf("%d\n",stt.tm_mday); mkst = mktime(&st); mkstt = mktime(&stt); lt = difftime(mkst , mkstt); printf("mkst = [%d]\n" , mkst); printf("mkstt = [%d]\n" , mkstt); b = (int)(lt/(3600*24)); printf("b = [%d]\n" , b); return b; } int main() { int i; i = CheckTime("200803150000","200803040000"); printf("%d\n",i); } |
原帖由 涩兔子 于 2008-3-13 23:06 发表
你可以参考一下 http://trac.lcuc.org.cn/public/t ... /test_dateandtime.c
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |