FILETIME to __int64

后端 未结 6 2107
日久生厌
日久生厌 2021-01-04 10:11

What is the proper way to convert a FILETIME structure into __int64? Can you please tell me?

6条回答
  •  太阳男子
    2021-01-04 10:43

    I had exactly the same issue, googled for it, and came here. But I also found a useful Microsoft support page at
    https://support.microsoft.com/en-gb/help/188768/info-working-with-the-filetime-structure

    It says:


    Performing Arithmetic with File Times

    It is often necessary to perform a simple arithmetic on file times. For example, you might need to know when a file is 30 days old. To perform an arithmetic on a file time, you need to convert the FILETIME to a quadword (a 64-bit integer), perform the arithmetic, and then convert the result back to a FILETIME.

    Assuming ft is a FILETIME structure containing the creation time of a file, the following sample code adds 30 days to the time:

       ULONGLONG qwResult;
    
       // Copy the time into a quadword.
       qwResult = (((ULONGLONG) ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
    
       // Add 30 days.
       qwResult += 30 * _DAY;
    
       // Copy the result back into the FILETIME structure.
       ft.dwLowDateTime  = (DWORD) (qwResult & 0xFFFFFFFF );
       ft.dwHighDateTime = (DWORD) (qwResult >> 32 );
    

    Edit: I realise this merely confirms some of the other answers, but I thought it was worth adding for clarification.

提交回复
热议问题