C库 - time.h

time.h 标题定义了四种变量类型,两种用于操作日期和时间的宏和各种函数.

库变量

以下是标题time.h中定义的变量类型 :

Sr.No.变量&描述
1

size_t

这是无符号整数类型,是 sizeof 关键字的结果.

2

clock_t

这是一种适合存储处理器时间的类型.

3

time_t

这是一种适合存储日历时间的类型.

4

struct tm

这是一个用于保存时间和日期的结构.

tm结构具有以下结构定义 :

struct tm {
   int tm_sec;         /* seconds,  range 0 to 59          */
   int tm_min;         /* minutes, range 0 to 59           */
   int tm_hour;        /* hours, range 0 to 23             */
   int tm_mday;        /* day of the month, range 1 to 31  */
   int tm_mon;         /* month, range 0 to 11             */
   int tm_year;        /* The number of years since 1900   */
   int tm_wday;        /* day of the week, range 0 to 6    */
   int tm_yday;        /* day in the year, range 0 to 365  */
   int tm_isdst;       /* daylight saving time             */
};

库宏

以下是标题time.h中定义的宏 :

Sr.No.Macro&描述
1

NULL

这个宏是空指针常量的值.

2

CLOCKS_PER_SEC

此宏表示每秒的处理器时钟数.

库函数

以下是标题time.h中定义的函数 :

Sr.No.功能&描述
1char * asctime(const struct tm * timeptr)

返回指向字符串的指针,该字符串表示日期和时间结构timeptr.

2clock_t clock(void)

返回自此以后使用的处理器时钟时间一个实现定义时代的开始(通常是程序的开始).

3char * ctime(const time_t * timer)

根据参数计时器返回表示本地时间的字符串.

4double difftime(time_t time1,time_t time2)

返回time1和time2(time1-time2)之间的秒数差异.

5struct tm * gmtime(const time_t * timer)

计时器的值被分解为结构tm并表示为协调世界时(UTC)也称为格林威治标准时间(GMT).

6struct tm * localtime(const time_t * timer)

计时器的值被分解为结构tm并以本地时区表示.

7time_t mktime(struct tm * timeptr)

根据本地时区将timeptr指向的结构转换为time_t值.

8size_t strftime(char * str ,size_t maxsize,const char * format,const struct tm * timeptr)

根据格式定义的格式规则格式化结构timeptr中表示的时间并存储到str.

9time_t time(time_t * timer)

计算当前日历时间并将其编码为time_t格式.