1 #include<time.h> 2 #include<stdio.h> 3 int main() 4 { 5 time_t timep; 6 struct tm *p; 7 time (&timep); 8 p=gmtime(&timep); 9 printf("%d\n",p->tm_sec); /*獲取當前秒*/ 10 printf("%d\n",p->tm_min); /*獲取當前分*/ 11 printf("%d\n",8+p->tm_hour);/*獲取當前時,這里獲取西方的時間,剛好相差八個小時*/ 12 printf("%d\n",p->tm_mday);/*獲取當前月份日數,范圍是1-31*/ 13 printf("%d\n",1+p->tm_mon);/*獲取當前月份,范圍是0-11,所以要加1*/ 14 printf("%d\n",1900+p->tm_year);/*獲取當前年份,從1900開始,所以要加1900*/ 15 printf("%d\n",p->tm_yday); /*從今年1月1日算起至今的天數,范圍為0-365*/ 16 return 0; 17 }
