SYSTEMTIME 与 time_t 互转函数

时间:2014-07-22 23:02:34   收藏:0   阅读:599
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 互转函数,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!