目录

C Library - <time.h>

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

Library变量 (Library Variables)

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

Sr.No. 变量和描述
1

size_t

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

2

clock_t

这是适合存储处理器时间的类型。

3

time_t is

这是适合存储日历时间的类型。

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             */
};

Library宏 (Library Macros)

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

Sr.No. 宏观和描述
1

NULL

此宏是空指针常量的值。

2

CLOCKS_PER_SEC

该宏表示每秒的处理器时钟数。

Library 函数

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

Sr.No. 功能说明
1 char * asctime(const struct tm * timeptr)

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

2 clock_t clock(void)

返回自实现定义时代开始以来使用的处理器时钟时间(通常是程序的开头)。

3 char * ctime(const time_t * timer)

返回表示基于参数计时器的本地时间的字符串。

4 double difftime(time_t time1,time_t time2)

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

5 struct tm * gmtime(const time_t * timer)

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

6 struct tm * localtime(const time_t * timer)

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

7 time_t mktime(struct tm * timeptr)

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

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

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

9 time_t time(time_t * timer)

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

↑回到顶部↑
WIKI教程 @2018