c语言时间日期函数总结(C language time and date function summary)
c语言时间日期函数总结(C language time and date function summary)
C language time and date function summary
Data structure used:
Time_t is a long type that represents machine time and can be obtained by the time () function.
The calendar time is represented by a (char *) type string. Format: week, month, day, hour: Minutes: seconds, years, \n\0
May be obtained by the function CTime () asctime ().
The temporal structure defined by the TM structure is defined as follows tm:
Struct TM {can be obtained by the function Localtime (), gmtime ()
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;};
/ / system date
Struct date {
Int da_year; / * * / Year - 1980
Char da_day Day of the month; / * * /
Char da_mon Month (Jan = 1; / * * /});
Time / system
Struct time {
Unsigned char ti_min; / * * / Minutes
Unsigned char ti_hour; / * * / Hours
Unsigned char ti_hund Hundredths of seconds; / * * /
Unsigned char ti_sec Seconds; / * * /};
Function used:
Char * asctime (struct TM * PTR) converts the time of the TM structure to the calendar time.
Char *ctime (long time) converts machine time into calendar time.
Struct TM *gmtime (time_t *time) converts machine time into TM time
When the PTR is empty, the machine time is obtained; the machine time is set at non empty time.
Time_t time (time_t *ptr) gets or sets machine time
Double difftime (time_t, time2, time_t, time1) gets two machine time differences, in seconds
Long dostounix (struct, data, *d, time, *t, struct) converts the date and time format of DOS to the UNIX standard
(machine time (used in dos.h libraries)
无效unixtodos(长将日期* D,结构,结构时间* T)
将UNIX格式的时间和日期转换成DOS格式(由时间和日期两部分组成,只能由机器时间得到,并且用到DOS。H库)
void getDate(struct日期* D)得到系统日期,D存放得到的日期信息
无效设置日期(struct日期* D)
无效时间(struct日期* T)得到系统时间D存放得到的时间信息
无效时间(struct日期* T)
C语言的标准库函数包括一系列日期和时间处理函数,它们都在头文件中说明。下面列出了这些函数。
在头文件中定义了三种类型:time_t,struct tm和clock_t。
在中说明的C语言时间函数
time_t时间(time_t *定时器);
双difftime(time_t time_t 1,2);
结构TM gmtime(const time_