所以我的代码基本上是这样的:
#include <time.h>
struct tm time_check;
time_check.tm_year = 2018;
time_check.tm_mon = 03;
time_check.tm_mday = 28;
if(mktime(&time_check) != -1)
条件每次都是错误的,但为什么?日期是正确的,不是吗?
最佳答案
需要初始化tm结构,年份要减去1900。 试试这个代码:
struct tm time_check;
time_t now;
time( &now );
localtime_s( &time_check, &now );
time_check.tm_year = 2018-1900;
time_check.tm_mon = 03;
time_check.tm_mday = 28;
if( mktime( &time_check ) != -1 )
关于c++ - mktime(&time_check) 只返回 "-1",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52065767/