C++ mktime changes value of my tm_struct

2019-07-30 06:15发布

I read bMonth from user;

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

Why mktime changes the values?

标签: c++ c mktime
1条回答
戒情不戒烟
2楼-- · 2019-07-30 06:42

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.

查看更多
登录 后发表回答