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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言中time相关函数

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

工作中遇到的函數:

int seed = time(NULL);

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

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

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

c語言中time函數的用法

標簽:?語言ctimerstruct日歷null ?分類: C語言(3)? 頭文件time.h? @函數名稱: ? ? localtime? 函數原型: ? ? struct tm *localtime(const time_t *timer)? 函數功能: ? ? 返回一個以tm結構表達的機器時間信息? 函數返回: ? ? 以tm結構表達的時間,結構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;??
  • ?????};???


  • 參數說明: ? ? timer-使用time()函數獲得的機器時間? [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;???
  • }???
  • @函數名稱: ? ? asctime? 函數原型: ? ? char* asctime(struct tm * ptr)? 函數功能: ? ? 得到機器時間(日期時間轉換為ASCII碼)? 函數返回: ? ? 返回的時間字符串格式為:星期,月,日,小時:分:秒,年? 參數說明: ? ? 結構指針ptr應通過函數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;???
  • }???


  • @函數名稱: ? ? ctime? 函數原型: ? ? char *ctime(long time)? 函數功能: ? ? 得到日歷時間? 函數返回: ? ? 返回字符串格式:星期,月,日,小時:分:秒,年? 參數說明: ? ? time-該參數應由函數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;???
  • }???
  • @函數名稱: ? ? difftime? 函數原型: ? ? double difftime(time_t time2, time_t time1)? 函數功能: ? ? 得到兩次機器時間差,單位為秒? 函數返回: ? ? 時間差,單位為秒? 參數說明: ? ? time1-機器時間一,time2-機器時間二.該參數應使用time函數獲得? 所屬文件: ? ? <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;???
  • }???
  • @函數名稱: ? ? gmtime? 函數原型: ? ? struct tm *gmtime(time_t ?*time)? 函數功能: ? ? 得到以結構tm表示的時間信息? 函數返回: ? ? 以結構tm表示的時間信息指針? 參數說明: ? ? time-用函數time()得到的時間信息? 所屬文件: ? ? <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;???
  • }???
  • @函數名稱: ? ? time? 函數原型: ? ? time_t time(time_t *timer)? 函數功能: ? ? 得到機器的日歷時間或者設置日歷時間? 函數返回: ? ? 機器日歷時間? 參數說明: ? ? timer=NULL時得到機器日歷時間,timer=時間數值時,用于設置日歷時間,time_t是一個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;???
  • }???
  • @函數名稱: ? ? tzset? 函數原型: ? ? void tzset(void)? 函數功能: ? ? UNIX兼容函數,用于得到時區,在DOS環境下無用途? 函數返回:? 參數說明:? 所屬文件: ? ? <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;???
  • }??
  • 轉載于:https://www.cnblogs.com/the-tops/p/5900163.html

    總結

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

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。