當前位置:編程學習大全網 - 編程語言 - C語言函數的時間日期函數

C語言函數的時間日期函數

函數庫為time.h、dos.h

在時間日期函數裏,主要用到的結構有以下幾個:

總時間日期貯存結構tm

┌──────────────────────┐

│struct tm │

│{ │

│ int tm_sec; /*秒,0-59*/ │

│ int tm_min; /*分,0-59*/ │

│ int tm_hour; /*時,0-23*/ │

│ int tm_mday; /*天數,1-31*/ │

│ int tm_mon; /*月數,0-11*/ │

│ int tm_year; /*自1900的年數*/ │

│ int tm_wday; /*自星期日的天數0-6*/ │

│ int tm_yday; /*自1月1日起的天數,0-365*/ │

│ int tm_isdst; /*是否采用夏時制,采用為正數*/│

│} │

└──────────────────────┘

日期貯存結構date

┌───────────────┐

│struct date │

│{ │

│ int da_year; /*自1900的年數*/│

│ char da_day; /*天數*/ │

│ char da_mon; /*月數 1=Jan*/ │

│} │

└───────────────┘

時間貯存結構time

┌────────────────┐

│struct time │

│{ │

│ unsigned char ti_min; /*分鐘*/│

│ unsigned char ti_hour; /*小時*/│

│ unsigned char ti_hund; │

│ unsigned char ti_sec; /*秒*/ │

│ │

└────────────────┘char *ctime(long *clock)

本函數把clock所指的時間(如由函數time返回的時間)轉換成下列格式的

字符串:Mon Nov 21 11:31:54 1983\n\0

char *asctime(struct tm *tm)

本函數把指定的tm結構類的時間轉換成下列格式的字符串:

Mon Nov 21 11:31:54 1983\n\0

double difftime(time_t time2,time_t time1)

計算結構time2和time1之間的時間差距(以秒為單位)

struct tm *gmtime(long *clock)本函數把clock所指的時間(如由函數time返回的時間)

轉換成格林威治時間,並以tm結構形式返回

struct tm *localtime(long *clock)本函數把clock所指的時間(如函數time返回的時間)

轉換成當地標準時間,並以tm結構形式返回

void tzset()本函數提供了對UNIX操作系統的兼容性

long dostounix(struct date *dateptr,struct time *timeptr)

本函數將dateptr所指的日期,timeptr所指的時間轉換成UNIX格式,並返回

自格林威治時間1970年1月1日淩晨起到現在的秒數

void unixtodos(long utime,struct date *dateptr,struct time *timeptr)

本函數將自格林威治時間1970年1月1日淩晨起到現在的秒數utime轉換成

DOS格式並保存於用戶所指的結構dateptr和timeptr中

void getdate(struct date *dateblk)本函數將計算機內的日期寫入結構dateblk

中以供用戶使用

void setdate(struct date *dateblk)本函數將計算機內的日期改成

由結構dateblk所指定的日期

void gettime(struct time *timep)本函數將計算機內的時間寫入結構timep中,

以供用戶使用

void settime(struct time *timep)本函數將計算機內的時間改為

由結構timep所指的時間

long time(long *tloc)本函數給出自格林威治時間1970年1月1日淩晨至現在所經

過的秒數,並將該值存於tloc所指的單元中.

int stime(long *tp)本函數將tp所指的時間(例如由time所返回的時間)

寫入計算機中.

  • 上一篇:園藝專業畢業生自我介紹
  • 下一篇:劃痕手勢編程
  • copyright 2024編程學習大全網