time_t和SYSTEMTIME之间的相互转换
/*
**time_t转SYSTEMTIME
*/
SYSTEMTIME TimetToSystemTime(time_t t)
{
FILETIME ft;
SYSTEMTIME pst;
LONGLONG nLL = Int32x32To64(t, 10000000) + 116444736000000000;
ft.dwLowDateTime = (DWORD)nLL;
ft.dwHighDateTime = (DWORD)(nLL >> 32);
FileTimeToSystemTime(&ft, &pst);
return pst;
}
/*
**SYSTEMTIME转time_t
*/
time_t SystemTimeToTimet(SYSTEMTIME st)
{
FILETIME ft;
SystemTimeToFileTime( &st, &ft );
LONGLONG nLL;
ULARGE_INTEGER ui;
ui.LowPart = ft.dwLowDateTime;
ui.HighPart = ft.dwHighDateTime;
nLL = (ft.dwHighDateTime << 32) + ft.dwLowDateTime;
time_t pt = (long)((LONGLONG)(ui.QuadPart - 116444736000000000) / 10000000);
return pt;
}
/*
**time_t转SYSTEMTIME
*/
SYSTEMTIME Time_tToSystemTime(time_t t)
{
tm temptm = *localtime(&t);
SYSTEMTIME st = {1900 + temptm.tm_year,
1 + temptm.tm_mon,
temptm.tm_wday,
temptm.tm_mday,
temptm.tm_hour,
temptm.tm_min,
temptm.tm_sec,
0};
return st;
}
/*
**SYSTEMTIME转time_t
*/
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);
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步