Reputation: 11
I have problem.. I can not understand why Function MKTIME always return -1
#include <Windows.h>
#include <stdio.h>
#include <time.h>
using namespace std;
int main() {
time_t now = time(NULL);
struct tm today;
localtime_s(&today, &now);
today.tm_year += 1900;
today.tm_mon += 1;
time_t t_today = mktime(&today);
printf("%ld", (long)t_today);
return 0;
}
t_today is -1
Upvotes: 1
Views: 150
Reputation: 75062
mktime
can deal with only upto the year 3000. Adding 1900 to today.tm_year
will exceed this limit. (1970 + 1900 = 3870) Try smaller offset.
References:
Upvotes: 1