#include #include #include int dow(int yy, int mm, int dd){ struct tm tsruct; tsruct.tm_mday = dd; tsruct.tm_mon = mm-1; tsruct.tm_year = yy-1900; tsruct.tm_hour = 0; tsruct.tm_min = 0; tsruct.tm_sec = 1; tsruct.tm_isdst = -1; if(mktime(&tsruct)==-1) tsruct.tm_wday=7; // error return (tsruct.tm_wday); } void sysDate(int *yy, int *mm, int *dd){ time_t t; struct tm *tb; /* Get time into t */ t = time(NULL); /* Convert time value t into structure pointed to by tb */ tb = localtime(&t); *dd = tb->tm_mday; *mm = tb->tm_mon+1; *yy = tb->tm_year+1900; } void sysTime(int *hh, int *mm, int *ss){ time_t t; struct tm *tb; /* Get time into t */ t = time(NULL); /* Convert time value t into structure pointed to by tb */ tb = localtime(&t); *hh = tb->tm_hour; *mm = tb->tm_min; *ss = tb->tm_sec; } /* main(){ int dd,mm,yy,n; sysDate(&yy,&mm,&dd); n = dow(yy,mm,dd); printf("今天是 %i年%02i月%02i日",yy,mm,dd); printf("(星期%i)\n",n); return 0; } */