C++ mktime 更改我的 tm_struct 的值

标签 c++ c mktime

我从用户那里读取了 bMonth;

time_t timestamp = time(NULL);
tm* birthday = localtime(&timestamp);

birthday->tm_mon = bMonth-1;

// now the tm_mon is set corectly

time_t birthStamp = mktime(birthday);

// now the tm_mon is 0

为什么 mktime 会改变值?

最佳答案

mktime

A call to this function automatically adjusts the values of the members of timeptr if they are off-range or -in the case of tm_wday and tm_yday- if they have values that do not match the date described by the other members.

关于C++ mktime 更改我的 tm_struct 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19375113/

相关文章:

c - 为什么线程在 linux 中没有以正确的优先级运行

PHP mktime 和时区

php - mktime() 到 mysql 日期时间列?

c++ - OpenGL NURBS 曲面

c++ - 哪个串行设备连接到控制台(Linux)?

计算数组中重复的元素

c - VS 代码中的 "cannot open source file "vcruntime_string.h "(dependency of "string.h ")"

c++ - ld : symbol(s) not found

c++ - 在类构造函数中声明的变量的范围是什么?

c - mktime 显示不一致的输出