# 資訊: 使用 FILETIME 結構

##### 其他相關資訊
FILETIME 結構表示從西元 1601 1 月 1 後, 的 100 奈秒間隔數目。結構是由結合以形成單一的 64 位元值的兩個 32 位元值所組成。
``   typedef struct _FILETIME {     DWORD dwLowDateTime;     DWORD dwHighDateTime;   } FILETIME;				``

``   #define _SECOND ((int64) 10000000)   #define _MINUTE (60 * _SECOND)   #define _HOUR   (60 * _MINUTE)   #define _DAY    (24 * _HOUR)				``

### 使用檔案時間執行 Arithmetics

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

### 設定檔案時間

``   BOOL SetFileTime(     HANDLE hFile,                     // Handle to the file.     CONST FILETIME *lpCreationTime,   // Time the file was created.     CONST FILETIME *lpLastAccessTime, // Time the file was last accessed.     CONST FILETIME *lpLastWriteTime   // Time the file was last                                       // written to.   );				``

``   BOOL bResult;   HANDLE hFile = CreateFile( szFilename,      GENERIC_WRITE, // The file must be opened with write access.      FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );   if (hFile != INVALID_HANDLE_VALUE) {      bResult = SetFileTime( hFile, &ft, NULL, NULL );      CloseHandle(hFile);   }				``

### 顯示檔案的時間

``   BOOL FileTimeToLocalFileTime(     CONST FILETIME *lpFileTime,  // Pointer to UTC file time to convert.     LPFILETIME lpLocalFileTime   // Pointer to converted file time.   );``

``   BOOL FileTimeToSystemTime(     CONST FILETIME *lpFileTime, // Pointer to file time to convert.     LPSYSTEMTIME lpSystemTime   // Pointer to structure to receive   );                            // system time.				``
[SYSTEMTIME 結構它表示日期和時間使用個別成員的月、 天、 年、 週間日、 小時、 分鐘、 第二個和毫秒。

``   int GetDateFormat(     LCID Locale,              // Locale for which date is to be formatted.     DWORD dwFlags,            // Flags specifying function options.     CONST SYSTEMTIME *lpDate, // Date to be formatted.     LPCTSTR lpFormat,         // Date format string.     LPTSTR lpDateStr,         // Buffer for storing formatted string.     int cchDate               // Size of buffer.   );   int GetTimeFormat(     LCID Locale,              // Locale for which time is to be formatted.     DWORD dwFlags,            // Flags specifying function options.     CONST SYSTEMTIME *lpTime, // Time to be formatted.     LPCTSTR lpFormat,         // Time format string.     LPTSTR lpTimeStr,         // Buffer for storing formatted string.     int cchTime               // Size of buffer.   );				``

``   SYSTEMTIME st;   char szLocalDate[255], szLocalTime[255];   FileTimeToLocalFileTime( &ft, &ft );   FileTimeToSystemTime( &ft, &st );   GetDateFormat( LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL,     szLocalDate, 255 );   GetTimeFormat( LOCALE_USER_DEFAULT, 0, &st, NULL, szLocalTime, 255 );   printf( "%s %s\n", szLocalDate, szLocalTime );				``

#### 警告：本文為自動翻譯

Microsoft Win32 Application Programming Interface

• kbmt kbapi kbdatetime kbfileio kbinfo kbkernbase KB188768 KbMtzh