time_t tmToTime_t(char * dt)
{
tm timeinfo;
sscanf_s(dt, "%d-%d-%d %d:%d:%d",
&timeinfo.tm_year, &timeinfo.tm_mon, &timeinfo.tm_mday,
&timeinfo.tm_hour, &timeinfo.tm_min, &timeinfo.tm_sec);
timeinfo.tm_year -= 1900;
timeinfo.tm_mon -= 1; //month: 0-11
return mktime(&timeinfo);
}
time_t SystemTimeToTime_t(const SYSTEMTIME& st)
{tm temptm = { st.wSecond,
st.wMinute,
st.wHour,
st.wDay,
st.wMonth - 1,
st.wYear - 1900,
st.wDayOfWeek,
0,
0 };
return mktime(&temptm);
}
SYSTEMTIME TimetToSystemTime(time_t t)
{
FILETIME ft;
SYSTEMTIME pst;
//LONGLONG nLL = Int32x32To64(t, 10000000) + 116444736000000000; 时间相差8小时
LONGLONG nLL = Int32x32To64(t, 10000000) + 116445024000000000;
ft.dwLowDateTime = (DWORD) nLL;
ft.dwHighDateTime = (DWORD) (nLL >> 32);
FileTimeToSystemTime(&ft, &pst);
return pst;
}