免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
time
  1. #include <stdio.h> 
  2.   #include <stdlib.h> /* 包含標(biāo)準(zhǔn)庫頭文件 */ 
  3.   #include <sys/time.h> 
  4.     
  5.   int main(int argc, char **argv) 
  6.   { 
  7.   struct timeval start,stop,diff; 
  8.   gettimeofday(&start,0); 
  9.                     //做你要做的事... 
  10.   gettimeofday(&stop,0); 
  11.   timeval_subtract(&diff,&start,&stop); 
  12.                     printf("總計(jì)用時:%d 微秒\n",diff.tv_usec); 
  13.   } 
  14.     
  15.   /** 
  16.       * 計(jì)算兩個時間的間隔,得到時間差 
  17.       * @param struct timeval* resule 返回計(jì)算出來的時間 
  18.       * @param struct timeval* x 需要計(jì)算的前一個時間 
  19.       * @param struct timeval* y 需要計(jì)算的后一個時間 
  20.       * return -1 failure ,0 success 
  21.   **/ 
  22.   int timeval_subtract(struct timeval* result, struct timeval* x, struct timeval* y) 
  23.   { 
  24.         int nsec; 
  25.     
  26.         if ( x->tv_sec>y->tv_sec ) 
  27.                   return -1; 
  28.     
  29.         if ( (x->tv_sec==y->tv_sec) && (x->tv_usec>y->tv_usec) ) 
  30.                   return -1; 
  31.     
  32.         result->tv_sec = ( y->tv_sec-x->tv_sec ); 
  33.         result->tv_usec = ( y->tv_usec-x->tv_usec ); 
  34.     
  35.         if (result->tv_usec<0) 
  36.         { 
  37.                   result->tv_sec -= 1; 
  38.                   result->tv_usec+=1000000; 
  39.         } 
  40.     
  41.         return 0; 
  42.   }


=========================================================================
  1. --------------------------------------------------
  2. #include <sys/time.h> 
  3.   #include <unistd.h> 
  4.   int gettimeofday(struct timeval *tv,struct timezone *tz); 
  5.   功能:將目前的時間以tv所指的結(jié)構(gòu)返回。 
  6.   struct timeval{ 
  7.           long tv_sec;//秒 
  8.           long tv_usec;//微秒 
  9.   }; 
  10.   將其中的tv_usec轉(zhuǎn)換到毫秒即可。 
  11.   timezone結(jié)構(gòu)自己查吧
  12.  
  13.  
  14.  
  15. 附錄:
  16. -------------------------------------------------
  17. Linux下獲得系統(tǒng)時間的C語言的實(shí)現(xiàn)方法 
  18.   #include<time.h> //C語言的頭文件 
  19.   #include<stdio.h> //C語言的I/
  20.     
  21.   void main() 
  22.   { 
  23.   time_t now; //實(shí)例化time_t結(jié)構(gòu) 
  24.   struct tm *timenow; //實(shí)例化tm結(jié)構(gòu)指針 
  25.   time(&now); 
  26.   //time函數(shù)讀取現(xiàn)在的時間(國際標(biāo)準(zhǔn)時間非北京時間),然后傳值給now 
  27.     
  28.   timenow = localtime(&now); 
  29.   //localtime函數(shù)把從time取得的時間now換算成你電腦中的時間(就是你設(shè)置的地區(qū)) 
  30.     
  31.   printf("Local time is %s\n",asctime(timenow)); 
  32.   //上句中asctime函數(shù)把時間轉(zhuǎn)換成字符,通過printf()函數(shù)輸出 
  33.   } 
  34.     
  35.   注釋:time_t是一個在time.h中定義好的結(jié)構(gòu)體。而tm結(jié)構(gòu)體的原形如下: 
  36.     
  37.   struct tm 
  38.   { 
  39.       int tm_sec;//seconds 0-61 
  40.       int tm_min;//minutes 1-59 
  41.       int tm_hour;//hours 0-23 
  42.       int tm_mday;//day of the month 1-31 
  43.       int tm_mon;//months since jan 0-11 
  44.       int tm_year;//years from 1900 
  45.       int tm_wday;//days since Sunday, 0-
  46.       int tm_yday;//days since Jan 1, 0-365 
  47.       int tm_isdst;//Daylight Saving time indicator 
  48.   };
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
(一)linux下的定時或計(jì)時操作(gettimeofday等的用法,秒,微妙,納秒)_鮑...
Linux獲取精確日歷函數(shù)
gettimeofday() -- 獲取當(dāng)前時間
c函數(shù)之gettimeofday()函數(shù)獲取系統(tǒng)時間
C語言的那些小秘密之volatile
gettimeofday
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服