본문 바로가기

Windows/MFC

FILETIME <-> time_t 변환

http://hykim001.egloos.com/6492952


static const __int64 SECS_BETWEEN_EPOCHS = 11644473600;
static const __int64 SECS_TO_100NS = 10000000; /* 10^7 */
time_t FileTimeToUnixTime(FILETIME FileTime, long* nsec)
{
    __int64 UnixTime;
    /* get the full win32 value, in 100ns */
    UnixTime = ((__int64)FileTime.dwHighDateTime << 32) + FileTime.dwLowDateTime;
    /* convert to the Unix epoch */
    UnixTime = UnixTime - (SECS_BETWEEN_EPOCHS * SECS_TO_100NS);

    if ( nsec )
    {
        /* get the number of 100ns, convert to ns */
        *nsec = (UnixTime % SECS_TO_100NS) * 100;
    }
    
    UnixTime /= SECS_TO_100NS; /* now convert to seconds */
    
    if ( (time_t)UnixTime != UnixTime )
    {
        assert(0);
    }

    return (time_t)UnixTime;
}

void UnixTimeToFileTime(time_t t, FILETIME * pft)
{
    // Note that LONGLONG is a 64-bit value
    LONGLONG ll;
    ll = Int32x32To64(t, 10000000) + 116444736000000000;
    pft->dwLowDateTime = (DWORD)ll;
    pft->dwHighDateTime = ll >> 32;
}

void UnixTimeToSystemTime(time_t t, LPSYSTEMTIME pst)
{
    FILETIME ft;

    UnixTimeToFileTime(t, &ft);
    FileTimeToSystemTime(&ft, pst);
}



출처 : time_t FILEFileTimeToUnixTime(FILETIME FileTime, long* nsec)
http://dotnet.di.unipi.it/Content/sscli/docs/doxygen/pal/filetime_8h.html#a4
http://dotnet.di.unipi.it/Content/sscli/docs/doxygen/pal/filetime_8c-source.html

'Windows > MFC' 카테고리의 다른 글

SFU  (0) 2013.10.02
SFU (Service for Unix) NFS Sever windows version  (0) 2013.10.02
인증  (0) 2013.10.02
방법: 장치 프로젝트에서 인증서 가져오기 및 적용  (0) 2013.10.02
방법: CAB 파일 서명(장치)  (0) 2013.10.02