当你有时间的时候
通过这个结构:http://www.cplusplus.com/reference/ctime/tm/
可以看到这些值(例如,tm_sec、tm_min
)都是int
。
问题是我想将这些 int 存储在某个地方。
但我想使用int32_t
类型而不是int
,这样大小就固定了。
我能做些什么吗?
最佳答案
C++ 从 C 中获取 struct tm
类型。根据 C 标准,struct tm
的这些元素具有一定的范围:
C99 §7.23.1 Components of time
The
tm
structure shall contain at least the following members, in any order. The semantics of the members and their normal ranges are expressed in the comments.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
。
关于c++ - 获取固定大小整数形式的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18981960/