I am trying to convert SYSTEMTIME
to time_t
through the implementation I found in various forums.
time_t TimeFromSystemTime(const SYSTEMTIME * pTime)
{
struct tm tm;
memset(&tm, 0, sizeof(tm));
tm.tm_year = pTime->wYear - 1900; // EDIT 2 : 1900's Offset as per comment
tm.tm_mon = pTime->wMonth - 1;
tm.tm_mday = pTime->wDay;
tm.tm_hour = pTime->wHour;
tm.tm_min = pTime->wMinute;
tm.tm_sec = pTime->wSecond;
tm.tm_isdst = -1; // Edit 2: Added as per comment
return mktime(&tm);
}
But to my surprise, the tm
is carrying the data corresponds to the local time but the mktime()
returns the time_t
corresponds to the time in UTC.
Is this the way it works or am I missing anything here?
Thanks for the help in advance !!
EDIT 1: I want to convert the SYSTEMTIME
which carries my Local time as the time_t
exactly.
I am using this in the VC6 based MFC application.
EDIT 2: Modified Code.