gpt4 book ai didi

C++ mktime 更改我的 tm_struct 的值

转载 作者:太空宇宙 更新时间:2023-11-04 03:52:53 25 4
gpt4 key购买 nike

我从用户那里读取了 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com