获取固定大小整数的时间

时间:2013-09-24 12:43:31

标签: c++ time

当你有时间的时候 通过这种结构:http://www.cplusplus.com/reference/ctime/tm/ 可以看到值(例如,tm_sec, tm_min)都是int。 问题是我想在某处存储这些int。 但我想使用int32_t类型而不是int,因此大小是固定的。 我能做些什么吗?

1 个答案:

答案 0 :(得分:3)

C ++从C获取struct tm类型。根据C标准,struct tm的这些元素具有一定的范围:

  

C99§7.23.1时间成分

     

tm结构应至少包含以下成员,任何顺序。成员的语义及其正常范围在注释中表示。

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

这些值可以安全地转换为int32_t