精確時間

  1. void sysLocalTime()  
  2. {  
  3.     time_t             timesec;  
  4.     struct tm         *p;  
  5.       
  6.       
  7.     time(×ec);  
  8.     p = localtime(×ec);  
  9.       
  10.     printf("%d%d%d%d%d%d\n", 1900+p->tm_year, 1+p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);  
  11.       
  12. }  
  13.   
  14. void sysUsecTime()  
  15. {  
  16.     struct timeval    tv;  
  17.     struct timezone tz;  
  18.       
  19.     struct tm         *p;  
  20.       
  21.     gettimeofday(&tv, &tz);  
  22.     printf("tv_sec:%ld\n",tv.tv_sec);  
  23.     printf("tv_usec:%ld\n",tv.tv_usec);  
  24.     printf("tz_minuteswest:%d\n",tz.tz_minuteswest);  
  25.     printf("tz_dsttime:%d\n",tz.tz_dsttime);  
  26.       
  27.     p = localtime(&tv.tv_sec);  
  28.     printf("time_now:%d%d%d%d%d%d.%ld\n", 1900+p->tm_year, 1+p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec);  
  29. }  
發佈了30 篇原創文章 · 獲贊 54 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章