久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      linux有獲取時(shí)間的函數(shù)嗎

      linux有獲取時(shí)間的函數(shù)。linux常用的時(shí)間函數(shù):1、time()函數(shù),獲取當(dāng)前的時(shí)間;2、“l(fā)ocaltime_r”()和localtime()函數(shù),取得當(dāng)?shù)啬壳皶r(shí)間和日期;3、gettimeofday()函數(shù),也可以獲取當(dāng)前的時(shí)間。

      linux有獲取時(shí)間的函數(shù)嗎

      本教程操作環(huán)境:linux7.3系統(tǒng)、Dell G3電腦。

      linux獲取時(shí)間的函數(shù)

      常用的時(shí)間函數(shù)介紹:

      1. time() 函數(shù)獲取當(dāng)前時(shí)間
        #include <time.h> time_t time(time_t *t);    /* 此函數(shù)會(huì)返回從公元1970年1月1日的UTC時(shí)間從0時(shí)0分0秒算起到現(xiàn)在所經(jīng)過的秒數(shù)。  * 如果t 并非空指針的話,此函數(shù)也會(huì)將返回值存到t指針?biāo)傅膬?nèi)存。  */

        實(shí)例代碼:

        #include <stdio.h> #include <string.h> #include <time.h>  int main() {     time_t sec;      sec = time((time_t *)NULL);     printf("%dn", (int)sec);      return 0; }

        運(yùn)行結(jié)果:

        linux有獲取時(shí)間的函數(shù)嗎

      2. localtime_r() localtime()取得當(dāng)?shù)啬壳皶r(shí)間和日期

        #include <time.h>             struct tm *localtime(const time_t *timep);     struct tm *localtime_r(const time_t *timep, struct tm *result);          /*該函數(shù)將有time函數(shù)獲取的值timep轉(zhuǎn)換真實(shí)世界所使用的時(shí)間日期表示方法,然后將結(jié)果由結(jié)構(gòu)tm返回*/  /**需要注意的是localtime函數(shù)可以將時(shí)間轉(zhuǎn)換本地時(shí)間,但是localtime函數(shù)不是線程安全的。 多線程應(yīng)用里面,應(yīng)該用localtime_r函數(shù)替代localtime函數(shù),因?yàn)閘ocaltime_r是線程安全的**/

        實(shí)例代碼:

        #include <stdio.h> #include <string.h> #include <time.h>  int main() {     time_t tmp;        struct tm *timp;          time(&tmp);        timp = localtime(&tmp);         printf("%d-%d-%d %d:%d:%dn", (1900 + timp->tm_year), ( 1 + timp->tm_mon), timp->tm_mday,                                 (timp->tm_hour), timp->tm_min, timp->tm_sec);       return 0; }

        運(yùn)行結(jié)果:

        linux有獲取時(shí)間的函數(shù)嗎

      3. asctime() asctime_r() 將時(shí)間和日期以字符串格式返回

        #include <time.h>             struct tm *gmtime(const time_t *timep);     struct tm *gmtime_r(const time_t *timep, struct tm *result);             char *asctime(const struct tm *tm);     char *asctime_r(const struct tm *tm, char *buf);                 /*  *gmtime是把日期和時(shí)間轉(zhuǎn)換為格林威治(GMT)時(shí)間的函數(shù)。  *將參數(shù)time 所指的time_t 結(jié)構(gòu)中的信息轉(zhuǎn)換成真實(shí)世界所使用的時(shí)間日期表示方法,然后將結(jié)果由結(jié)構(gòu)tm返回  *asctime 將時(shí)間以換為字符串字符串格式返回   */

        實(shí)例代碼:

        #include <stdio.h> #include <string.h> #include <time.h>     int main()  {        time_t timp;        time(&timp);         printf("%sn", asctime(gmtime(&timp)));             return 0; }

        運(yùn)行結(jié)果:(asctime獲取的字符串自己帶有換行符)

        linux有獲取時(shí)間的函數(shù)嗎

      4. ctime(),ctime_r() 將時(shí)間和日期以字符串格式表示

        #include <time.h> char *ctime(const time_t *timep); char *ctime_r(const time_t *timep, char *buf);   /*  *ctime()將參數(shù)timep所指的time_t結(jié)構(gòu)中的信息轉(zhuǎn)換成真實(shí)世界所使用的時(shí)間日期表示方法,  *然后將結(jié)果以字符串形態(tài)返回  */

        實(shí)例代碼:

        #include <stdio.h> #include <string.h> #include <time.h>     int main(void)    {        time_t tmp;       time(&tmp);        printf("%sn", ctime(&tmp));          return 0;   }

        運(yùn)行結(jié)果:(ctime獲取的字符串自己帶有換行符)

        linux有獲取時(shí)間的函數(shù)嗎

      5. mktime() 將時(shí)間結(jié)構(gòu)體struct tm的值轉(zhuǎn)化為經(jīng)過的秒數(shù)

         #include <time.h>  time_t mktime(struct tm *tm);  /*  *將時(shí)間結(jié)構(gòu)體struct tm的值轉(zhuǎn)化為經(jīng)過的秒數(shù)  */

        實(shí)例代碼 :

        #include <stdio.h> #include <string.h> #include <time.h>     int main()    {        time_t tmp;        struct tm *timp;         time(&tmp);        timp = localtime(&tmp);        tmp = mktime(timp);         printf("%dn", (int)tmp);             return 0; }

        運(yùn)行結(jié)果:

        linux有獲取時(shí)間的函數(shù)嗎

      6. gettimeofday() 獲取當(dāng)前時(shí)間

        #include <sys/time.h>  int gettimeofday(struct timeval *tv, struct timezone *tz);      struct timeval {     time_t      tv_sec;     /* seconds (秒)*/     suseconds_t tv_usec;    /* microseconds(微秒) */     }; struct timezone {     int tz_minuteswest;     /* minutes west of Greenwich */     int tz_dsttime;         /* type of DST correction */     }; /*  *gettimeofday函數(shù)獲取當(dāng)前時(shí)間存于tv結(jié)構(gòu)體中,相應(yīng)的時(shí)區(qū)信息則存于tz結(jié)構(gòu)體中  *需要注意的是tz是依賴于系統(tǒng),不同的系統(tǒng)可能存在獲取不到的可能,因此通常設(shè)置為NULL  */

        實(shí)例代碼:

        #include <stdio.h> #include <string.h> #include <sys/time.h>  int main() {     struct timeval tv;           gettimeofday(&tv, NULL);      printf("tv_sec = %dn", (int)tv.tv_sec);     printf("tv_usec = %dn", (int)tv.tv_usec);          return 0; }

        運(yùn)行結(jié)果:

        linux有獲取時(shí)間的函數(shù)嗎

      推薦學(xué)習(xí):Linux視頻教程

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)