• <output id="aynwq"><form id="aynwq"><code id="aynwq"></code></form></output>

    <mark id="aynwq"><option id="aynwq"></option></mark>
  • <mark id="aynwq"><option id="aynwq"></option></mark><label id="aynwq"><dl id="aynwq"></dl></label>
  • 學習啦 > 學習英語 > 專業英語 > 計算機英語 > c語言中time函數的用法

    c語言中time函數的用法

    時間: 長思709 分享

    c語言中time函數的用法

      c語言中time函數的用法的用法你知道嗎?下面小編就跟你們詳細介紹下c語言中time函數的用法的用法,希望對你們有用。

      c語言中time函數的用法的用法如下:

      頭文件time.h

      @函數名稱: localtime

      函數原型: struct tm *localtime(const time_t *timer)

      函數功能: 返回一個以tm結構表達的機器時間信息

      函數返回: 以tm結構表達的時間,結構tm定義如下:

      [cpp] view plain copy

      01.struct tm{

      02. int tm_sec;

      03. int tm_min;

      04. int tm_hour;

      05. int tm_mday;

      06. int tm_mon;

      07. int tm_year;

      08. int tm_wday;

      09. int tm_yday;

      10. int tm_isdst;

      11. };

      參數說明: timer-使用time()函數獲得的機器時間

      [cpp] view plain copy

      01.#include <time.h>

      02.#include <stdio.h>

      03.#include <dos.h>

      04.int main() {

      05. time_t timer;

      06. struct tm *tblock;

      07. timer=time(NULL);

      08. tblock=localtime(&timer);

      09. printf("Local time is: %s",asctime(tblock));

      10. return 0;

      11.}

      @函數名稱: asctime

      函數原型: char* asctime(struct tm * ptr)

      函數功能: 得到機器時間(日期時間轉換為ASCII碼)

      函數返回: 返回的時間字符串格式為:星期,月,日,小時:分:秒,年

      參數說明: 結構指針ptr應通過函數localtime()和gmtime()得到

      所屬文件: <time.h>

      [cpp] view plain copy

      01.#include <stdio.h>

      02.#include <string.h>

      03.#include <time.h>

      04. int main() {

      05. struct tm t;

      06. char str[80];

      07. t.tm_sec=1;

      08. t.tm_min=3;

      09. t.tm_hour=7;

      10. t.tm_mday=22;

      11. t.tm_mon=11;

      12. t.tm_year=56;

      13. t.tm_wday=4;

      14. t.tm_yday=0;

      15. t.tm_isdst=0;

      16. strcpy(str,asctime(&t));

      17. printf("%s",str);

      18. return 0;

      19.}

      @函數名稱: ctime

      函數原型: char *ctime(long time)

      函數功能: 得到日歷時間

      函數返回: 返回字符串格式:星期,月,日,小時:分:秒,年

      參數說明: time-該參數應由函數time獲得

      所屬文件: <time.h>

      [cpp] view plain copy

      01.#include <stdio.h>

      02.#include <time.h>

      03.int main() {

      04. time_t t;

      05. time(&t);

      06. printf("Today's date and time: %s",ctime(&t));

      07. return 0;

      08.}

      @函數名稱: difftime

      函數原型: double difftime(time_t time2, time_t time1)

      函數功能: 得到兩次機器時間差,單位為秒

      函數返回: 時間差,單位為秒

      參數說明: time1-機器時間一,time2-機器時間二.該參數應使用time函數獲得

      所屬文件: <time.h>

      [cpp] view plain copy

      01.#include <time.h>

      02.#include <stdio.h>

      03.#include <dos.h>

      04.#include <conio.h>

      05.int main() {

      06. time_t first, second;

      07. clrscr();

      08. first=time(NULL);

      09. delay(2000);

      10. second=time(NULL);

      11. printf("The difference is: %f seconds",difftime(second,first));

      12. getch();

      13. return 0;

      14.}

      @函數名稱: gmtime

      函數原型: struct tm *gmtime(time_t *time)

      函數功能: 得到以結構tm表示的時間信息

      函數返回: 以結構tm表示的時間信息指針

      參數說明: time-用函數time()得到的時間信息

      所屬文件: <time.h>

      [cpp] view plain copy

      01.#include <stdio.h>

      02.#include <stdlib.h>

      03.#include <time.h>

      04.#include <dos.h>

      05.char *tzstr="TZ=PST8PDT";

      06.int main() {

      07. time_t t;

      08. struct tm *gmt, *area;

      09. putenv(tzstr);

      10. tzset();

      11. t=time(NULL);

      12. area=localtime(&t);

      13. printf("Local time is:%s", asctime(area));

      14. gmt=gmtime(&t);

      15. printf("GMT is:%s", asctime(gmt));

      16. return 0;

      17.}

      @函數名稱: time

      函數原型: time_t time(time_t *timer)

      函數功能: 得到機器的日歷時間或者設置日歷時間

      函數返回: 機器日歷時間

      參數說明: timer=NULL時得到機器日歷時間,timer=時間數值時,用于設置日歷時間,time_t是一個long類型

      所屬文件: <time.h>

      [cpp] view plain copy

      01.#include <time.h>

      02.#include <stdio.h>

      03.#include <dos.h>

      04.int main() {

      05. time_t t;

      06. t=time();

      07. printf("The number of seconds since January 1,1970 is %ld",t);

      08. return 0;

      09.}

      @函數名稱: tzset

      函數原型: void tzset(void)

      函數功能: UNIX兼容函數,用于得到時區,在DOS環境下無用途

      函數返回:

      參數說明:

      所屬文件: <time.h>

      [cpp] view plain copy

      01.#include <time.h>

      02.#include <stdlib.h>

      03.#include <stdio.h>

      04.int main() {

      05. time_t td;

      06. putenv("TZ=PST8PDT");

      07. tzset();

      08. time(&td);

      09. printf("Current time=%s",asctime(localtime(&td)));

      10. return 0;

      11.}

    533435 主站蜘蛛池模板: 城中村找个白皙丰满妇女在线播放| 日韩精品人妻系列无码专区免费 | 啊灬用力啊灬啊灬快灬深| 中文字幕亚洲综合久久综合| 精品国产v无码大片在线观看 | 日本最大色倩网站www| 四虎影视成人永久免费观看视频| 一区二区三区无码视频免费福利 | 亚洲国产一区在线观看| 黄色一级毛片免费看| 无码人妻精一区二区三区| 免费大片黄在线观看| 18精品久久久无码午夜福利| 日韩一级二级三级| 向日葵app看片视频| 99精品久久久中文字幕| 欧美办公室系列观看丝袜| 国产乱码一区二区三区爽爽爽| 一本大道香蕉在线影院| 母子俩肥水不流外人田| 国产成人综合在线视频| 东北美女野外bbwbbw免费| 欧美黑人粗大xxxxbbbb| 国产在线视频第一页| 一区二区三区无码高清视频| 欧美日韩在线电影| 国产人与禽zoz0性伦| jizz黄色片| 旧番拯救精灵森林第四集| 国产一区二区三区福利| 99久热只有精品视频免费看| 日韩精品国产丝袜| 免费无码专区毛片高潮喷水| 2022福利视频| 巨胸喷奶水视频www网免费| 亚洲免费在线观看| 红杏出墙电影在线观看| 国产精品无码av天天爽| 中文字幕在线视频一区| 欧美日韩精品一区二区三区在线 | 国产精品久久精品视|