給你寫了一個程式,應該能看懂的:
#include <stdio.h>
#include <time.h>
#include <memory.h>
int main(void)
{
time_t t1;
time_t t2;
struct tm OldTime;
struct tm NewTime;
memset(&OldTime,0x0,sizeof(tm));
OldTime.tm_year = 110;// 2010 年表示為 2010 - 1900 = 110
OldTime.tm_mon = 12;
OldTime.tm_mday = 6;
memset(&NewTime,0x0,sizeof(tm));
NewTime.tm_year = 111;// 2011 年表示為 2011 - 1900 = 111
NewTime.tm_mon = 12;
NewTime.tm_mday = 6;
t1 = mktime(&NewTime); //2011-12-6
t2 = mktime(&OldTime); //2010-12-6
printf("%d",(t1-t2)/(24*3600));
return 0;
}
給你寫了一個程式,應該能看懂的:
#include <stdio.h>
#include <time.h>
#include <memory.h>
int main(void)
{
time_t t1;
time_t t2;
struct tm OldTime;
struct tm NewTime;
memset(&OldTime,0x0,sizeof(tm));
OldTime.tm_year = 110;// 2010 年表示為 2010 - 1900 = 110
OldTime.tm_mon = 12;
OldTime.tm_mday = 6;
memset(&NewTime,0x0,sizeof(tm));
NewTime.tm_year = 111;// 2011 年表示為 2011 - 1900 = 111
NewTime.tm_mon = 12;
NewTime.tm_mday = 6;
t1 = mktime(&NewTime); //2011-12-6
t2 = mktime(&OldTime); //2010-12-6
printf("%d",(t1-t2)/(24*3600));
return 0;
}