时间和日期
#include <time.h> time_t time(time_t *calptr); 返回值:成功返回时间值,出错返回-1 |
localtime和gmtime将日历时间转换成分解的时间,并将这些存放在一个结构体中:
struct tm { int tm_sec; /* seconds */ int tm_min; /* minutes */ int tm_hour; /* hours */ int tm_mday; /* day of the month */ int tm_mon; /* month */ int tm_year; /* year */ int tm_wday; /* day of the week */ int tm_yday; /* day in the year */ int tm_isdst; /* daylight saving time */ }; |
#include <time.h> struct tm * gmtime(const time_t *calptr); struct tm *locatime(const time_t *calptr); 返回值:指向分解的tm结构的指针;出错返回NULL |
函数mktime以本地时间作为参数,将其变成time_t值。
#include <time.h> time_t mktime(struct tm *tmptr); 返回值:成功返回日历时间,出错返回-1 |