|
时间:2009/6/9/ 17/36/11
为什么刚刚好差10天呢?
printf:
- 1244568971
- 2009
- 6
- 19
- 17
- 36
- 11
复制代码
- #define IsLeapYear(y) ((!(y % 4)) ? (((!(y % 400)) && (y % 100)) ? 1 : 0) : 0)
- #define LEAPY (366*24*60*60)
- #define COMMONY (365*24*60*60)
- #define DAYINSECS (24*60*60)
- int main()
- {
- struct timeval tm;
- time_t itm;
- int i,j;
- int month,sec;
- int dtmp,htmp,mtmp;
- int mds[12]={31,28,31,30,31,30,31,31,30,31,30,31};
- gettimeofday(&tm,NULL);
- itm = tm.tv_sec;
- for(i=1970;;i++)
- {
- if(IsLeapYear(i) && (itm >= LEAPY))
- itm -= LEAPY;
- else if(!IsLeapYear(i) && (itm>=COMMONY))
- itm -= COMMONY;
- else
- break;
- }
-
- month = 1;
- for(j=0;j<12;j++)
- {
- if( (month==2) && IsLeapYear(i) && (itm>=(28*DAYINSECS)) )
- {
- itm-=(29*DAYINSECS);
- month=month+1;
- }
- else if( itm>=mds[j]*DAYINSECS )
- {
- itm-=(mds[j]*DAYINSECS);
- month=month+1;
- }
- else
- break;
- }
- dtmp = itm/(DAYINSECS);
- itm -= dtmp*DAYINSECS;
- htmp = itm/(60*60);
- itm -= htmp*60*60;
- mtmp = itm/60;
- sec = itm%60;
- printf("%d\n",tm.tv_sec);
- printf("%d\n",i);
- printf("%d\n",month);
- printf("%d\n",dtmp);
- printf("%d\n",htmp);
- printf("%d\n",mtmp);
- printf("%d\n",sec);
- return 0;
- }
复制代码 |
|