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);
}

SYSTEMTIME Time_tToSystemTime(time_t t)
{
    //tm temptm = *localtime_s(&t);
    tm temptm;
    localtime_s(&temptm,&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 互转函数)