struct tm和time_t

背景:今天看muduo库,发现 Date这个日期类的头问件Date.h,里面有一个结构体的声明:

struct tm;

然后在其源文件Date.cc中有一个头文件 #include<time.h>

这个tm应该就是time.h中定义的记录时间信息的头文件。

 

下面就来看一下这个结构体的内容和功能:

MemberTypeMeaningRange
tm_sec int seconds after the minute 0-60*
tm_min int minutes after the hour 0-59
tm_hour int hours since midnight 0-23
tm_mday int day of the month 1-31
tm_mon int months since January 0-11
tm_year int years since 1900  
tm_wday int days since Sunday 0-6
tm_yday int days since January 1 0-365
tm_isdst int Daylight Saving Time flag  

从上面的表不难看出,这个结构体就是保存着当前时间信息的结构体。包括:

秒  分  时  日  月   年  星期几    这一年中的第几天   

 

time_t 这种类型就是用来存储从1970年到现在经过了多少秒,要想更精确一点,可以用结构struct timeval,它精确到微妙。

posted @ 2020-09-11 14:16  熊鑫xxx1x  阅读(875)  评论(0)    收藏  举报