Reputation: 175
Using visual studio 2013, creating a standard win32 console application, mktime returns negative(-1) regardless of params passed.
Are there any reasons this code should fail this way? I can't tell that any combination of tm params passed makes any difference.
#include "stdafx.h"
#include <time.h>
int _tmain(int argc, _TCHAR* argv[])
{
struct tm stm;
stm.tm_sec = 27;
stm.tm_min = 5;
stm.tm_hour = 18;
stm.tm_mday = 2;
stm.tm_mon = 1;
stm.tm_year = 2015;
stm.tm_wday = 0;
stm.tm_yday = 0;
printf("%lld\n", mktime(&stm));//prints -1
return 0;
}
Upvotes: 0
Views: 760
Reputation: 11322
Your value 2015
for stm.tm_year
is invalid. Subtract 1900
es explained in MSDN.
Note that the month values start with 0 for January.
Upvotes: 5