时间获取相关函数mktime()、gmtime()
mktime()
函数原型:time_t mktime(struct tm *timeptr);
函数功能:将时间转换为自1970年1月1日以来逝去时间的秒数,发生错误时返回-1。也就是是把获取的时间转换成时间戳。
gmtime()
函数原型:struct tm *gmtime(const time_t *timeptr)
函数功能:返回tm结构的格林尼治时间(GMT)
其中的tm结构体定义如下:
头文件:time.h
struct tm {
int tm_sec; /* seconds after the minute, 0 to 60
(0 - 60 allows for the occasional leap second) */
int tm_min; /* minutes after the hour, 0 to 59 */
int tm_hour; /* hours since midnight, 0 to 23 */
int tm_mday; /* day of the month, 1 to 31 */
int tm_mon; /* months since January, 0 to 11 */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday, 0 to 6 */
int tm_yday; /* days since January 1, 0 to 365 */
int tm_isdst; /* Daylight Savings Time flag */
union {
/* ABI-required extra fields, in a variety of types */
struct {
int __extra_1, __extra_2;
};
struct {
long __extra_1_long, __extra_2_long;
};
struct {
char *__extra_1_cptr, *__extra_2_cptr;
};
struct {
void *__extra_1_vptr, *__extra_2_vptr