c++ - 获取固定大小整数形式的时间

标签 c++ time

当你有时间的时候 通过这个结构: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/

相关文章:

c++ - 通用生成文件

c++ - 如何使用(类似?)可变参数模板在 C++14 中编写位掩码

c++ - 如何将二维数组分配给 **pointer ?

c++ - 将值传递给构造函数的差异语法c++

c++ - c++ 中的 read() 函数类似于 c read()

powershell - 使用 PowerShell 获取 IIS 的具体回收时间

python - Python 中的时间不一致

java - android - SimpleDateFormat 以奇怪的方式解析数据。错误的月份或/和年份

c++ - 关于 C++ 中的 sleep 命令

c - 在 C 中以分钟为单位测量时间