日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

c语言中time相关函数

發(fā)布時(shí)間:2023/12/20 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言中time相关函数 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

工作中遇到的函數(shù):

int seed = time(NULL);

srand(seed);
signal(SIGINT, stop);
signal(SIGUSR1, sig_usr1);      搜time函數(shù)時(shí),看到相關(guān)time ? 函數(shù)的文章,粘貼如下:

-------------------------

from:http://blog.csdn.net/wangluojisuan/article/details/7045592

c語(yǔ)言中time函數(shù)的用法

標(biāo)簽:?語(yǔ)言ctimerstruct日歷null ?分類: C語(yǔ)言(3)? 頭文件time.h? @函數(shù)名稱: ? ? localtime? 函數(shù)原型: ? ? struct tm *localtime(const time_t *timer)? 函數(shù)功能: ? ? 返回一個(gè)以tm結(jié)構(gòu)表達(dá)的機(jī)器時(shí)間信息? 函數(shù)返回: ? ? 以tm結(jié)構(gòu)表達(dá)的時(shí)間,結(jié)構(gòu)tm定義如下:? [cpp]?view plaincopy
  • struct??tm{??
  • ???????int?tm_sec;??
  • ???????int?tm_min;??
  • ???????int?tm_hour;??
  • ???????int?tm_mday;??
  • ???????int?tm_mon;??
  • ???????int?tm_year;??
  • ???????int?tm_wday;??
  • ???????int?tm_yday;??
  • ???????int?tm_isdst;??
  • ?????};???


  • 參數(shù)說明: ? ? timer-使用time()函數(shù)獲得的機(jī)器時(shí)間? [cpp]?view plaincopy
  • #include?<time.h>???
  • #include?<stdio.h>???
  • #include?<dos.h>???
  • int?main()?{??
  • ?????time_t?timer;??
  • ?????struct?tm?*tblock;??
  • ?????timer=time(NULL);??
  • ?????tblock=localtime(&timer);??
  • ?????printf("Local?time?is:?%s",asctime(tblock));??
  • ?????return?0;???
  • }???
  • @函數(shù)名稱: ? ? asctime? 函數(shù)原型: ? ? char* asctime(struct tm * ptr)? 函數(shù)功能: ? ? 得到機(jī)器時(shí)間(日期時(shí)間轉(zhuǎn)換為ASCII碼)? 函數(shù)返回: ? ? 返回的時(shí)間字符串格式為:星期,月,日,小時(shí):分:秒,年? 參數(shù)說明: ? ? 結(jié)構(gòu)指針ptr應(yīng)通過函數(shù)localtime()和gmtime()得到? 所屬文件: ? ? <time.h>? [cpp]?view plaincopy
  • #include?<stdio.h>???
  • #include?<string.h>???
  • #include?<time.h>??
  • ?int?main()?{??
  • ?????struct?tm?t;??
  • ?????char?str[80];??
  • ?????t.tm_sec=1;??
  • ?????t.tm_min=3;??
  • ?????t.tm_hour=7;??
  • ?????t.tm_mday=22;??
  • ?????t.tm_mon=11;??
  • ?????t.tm_year=56;??
  • ?????t.tm_wday=4;??
  • ?????t.tm_yday=0;??
  • ?????t.tm_isdst=0;??
  • ?????strcpy(str,asctime(&t));??
  • ?????printf("%s",str);??
  • ?????return?0;???
  • }???


  • @函數(shù)名稱: ? ? ctime? 函數(shù)原型: ? ? char *ctime(long time)? 函數(shù)功能: ? ? 得到日歷時(shí)間? 函數(shù)返回: ? ? 返回字符串格式:星期,月,日,小時(shí):分:秒,年? 參數(shù)說明: ? ? time-該參數(shù)應(yīng)由函數(shù)time獲得? 所屬文件: ? ? <time.h>? [cpp]?view plaincopy
  • #include?<stdio.h>???
  • #include?<time.h>???
  • int?main()?{??
  • ?????time_t?t;??
  • ?????time(&t);??
  • ?????printf("Today's?date?and?time:?%s",ctime(&t));??
  • ?????return?0;???
  • }???
  • @函數(shù)名稱: ? ? difftime? 函數(shù)原型: ? ? double difftime(time_t time2, time_t time1)? 函數(shù)功能: ? ? 得到兩次機(jī)器時(shí)間差,單位為秒? 函數(shù)返回: ? ? 時(shí)間差,單位為秒? 參數(shù)說明: ? ? time1-機(jī)器時(shí)間一,time2-機(jī)器時(shí)間二.該參數(shù)應(yīng)使用time函數(shù)獲得? 所屬文件: ? ? <time.h>? [cpp]?view plaincopy
  • #include?<time.h>???
  • #include?<stdio.h>???
  • #include?<dos.h>???
  • #include?<conio.h>???
  • int?main()?{??
  • ?????time_t?first,?second;??
  • ?????clrscr();??
  • ?????first=time(NULL);??
  • ?????delay(2000);??
  • ?????second=time(NULL);??
  • ?????printf("The?difference?is:?%f?seconds",difftime(second,first));??
  • ?????getch();??
  • ?????return?0;???
  • }???
  • @函數(shù)名稱: ? ? gmtime? 函數(shù)原型: ? ? struct tm *gmtime(time_t ?*time)? 函數(shù)功能: ? ? 得到以結(jié)構(gòu)tm表示的時(shí)間信息? 函數(shù)返回: ? ? 以結(jié)構(gòu)tm表示的時(shí)間信息指針? 參數(shù)說明: ? ? time-用函數(shù)time()得到的時(shí)間信息? 所屬文件: ? ? <time.h>? [cpp]?view plaincopy
  • #include?<stdio.h>???
  • #include?<stdlib.h>???
  • #include?<time.h>???
  • #include?<dos.h>???
  • char?*tzstr="TZ=PST8PDT";???
  • int?main()?{??
  • ?????time_t?t;??
  • ?????struct?tm?*gmt,?*area;??
  • ?????putenv(tzstr);??
  • ?????tzset();??
  • ?????t=time(NULL);??
  • ?????area=localtime(&t);??
  • ?????printf("Local?time?is:%s",?asctime(area));??
  • ?????gmt=gmtime(&t);??
  • ?????printf("GMT?is:%s",?asctime(gmt));??
  • ?????return?0;???
  • }???
  • @函數(shù)名稱: ? ? time? 函數(shù)原型: ? ? time_t time(time_t *timer)? 函數(shù)功能: ? ? 得到機(jī)器的日歷時(shí)間或者設(shè)置日歷時(shí)間? 函數(shù)返回: ? ? 機(jī)器日歷時(shí)間? 參數(shù)說明: ? ? timer=NULL時(shí)得到機(jī)器日歷時(shí)間,timer=時(shí)間數(shù)值時(shí),用于設(shè)置日歷時(shí)間,time_t是一個(gè)long類型? 所屬文件: ? ? <time.h>? [cpp]?view plaincopy
  • #include?<time.h>???
  • #include?<stdio.h>???
  • #include?<dos.h>???
  • int?main()?{??
  • ?????time_t?t;??
  • ?????t=time();??
  • ?????printf("The?number?of?seconds?since?January?1,1970?is?%ld",t);??
  • ?????return?0;???
  • }???
  • @函數(shù)名稱: ? ? tzset? 函數(shù)原型: ? ? void tzset(void)? 函數(shù)功能: ? ? UNIX兼容函數(shù),用于得到時(shí)區(qū),在DOS環(huán)境下無(wú)用途? 函數(shù)返回:? 參數(shù)說明:? 所屬文件: ? ? <time.h>? [cpp]?view plaincopy
  • #include?<time.h>???
  • #include?<stdlib.h>???
  • #include?<stdio.h>???
  • int?main()?{??
  • ?????time_t?td;??
  • ?????putenv("TZ=PST8PDT");??
  • ?????tzset();??
  • ?????time(&td);??
  • ?????printf("Current?time=%s",asctime(localtime(&td)));??
  • ?????return?0;???
  • }??
  • 轉(zhuǎn)載于:https://www.cnblogs.com/the-tops/p/5900163.html

    總結(jié)

    以上是生活随笔為你收集整理的c语言中time相关函数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。