C/C++中的时间结构

来源:互联网 发布:钉钉软件安卓版 编辑:程序博客网 时间:2024/05/16 10:20

C/C++系统中,时间可以有两种分类方式,即 (1) 标准世界时UTC 和 本地时间 LT  (2)分解时间 (break-down time) 和 日历时间(calendar time). 标准时间和本地时间更多的适用于协调时间的一致性,而分解时间和日历时间则更多的用于编程中时间的存储。


在CRT和MS-VC系统中,有不同的结构 用于表示 分解时间 和 日历时间,总结如下:

1. CRT
<1> break-down time
struct tm { 
int tm_sec; /* 秒 – 取值区间为[0,59] */ //ms
int tm_min; /* 分 - 取值区间为[0,59] */ 
int tm_hour; /* 时 - 取值区间为[0,23] */ 
int tm_mday; /* 一个月中的日期 - 取值区间为[1,31] */ 
int tm_mon; /* 月份(从一月开始,0代表一月) - 取值区间为[0,11] */ 
int tm_year; /* 年份,其值等于实际年份减去1900 */ 
int tm_wday; /* 星期 – 取值区间为[0,6],其中0代表星期天,1代表星期一,以此类推 */ 
int tm_yday; /* 从每年的1月1日开始的天数 – 取值区间为[0,365],其中0代表1月1日,1代表1月2日,以此类推 */ 
int tm_isdst; /* 夏令时标识符,实行夏令时的时候,tm_isdst为正。不实行夏令时的进候,tm_isdst为0;不了解情况时,tm_isdst()为负。*/ 
}; 

<2> calendar time
typedef long time_t; /* 时间值, sec */ 



2. MS-VC
<1> system time
typedef struct _SYSTEMTIME {  
WORD wYear;  
WORD wMonth;  
WORD wDayOfWeek;  
WORD wDay;  
WORD wHour;  
WORD wMinute;  
WORD wSecond;  
WORD wMilliseconds;  
} SYSTEMTIME, *PSYSTEMTIME;//ms

<2> file time
typedef
struct _FILETIME {  
DWORD dwLowDateTime;  
DWORD dwHighDateTime;  
} FILETIME, *PFILETIME;// 100ns


可以看出,微软的SDK比标准C库提供的时间 更加精确