typedef struct _FILETIME {
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME, *PFILETIME, *LPFILETIME;
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *LPSYSTEMTIME;
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *LPSYSTEMTIME;
FILETIME和SYSTEMTIME都只是记录时间的结构。
GetLocalTime能够得到本地电脑设置时区的时间,得到的类型是SYSTEMTIME的类型。
常用转换函数:
LONG WINAPI CompareFileTime(const FILETIME *lpft1, const FILETIME *lpft2);
BOOL WINAPI FileTimeToSystemTime(const FILETIME *lpft, LPSYSTEMTIME lpst);
BOOL WINAPI SystemTimeToFileTime(const SYSTEMTIME *lpst, LPFILETIME lpft);
BOOL WINAPI FileTimeToLocalFileTime(const FILETIME *lpft, LPFILETIME lpftLocal);
BOOL WINAPI LocalFileTimeToFileTime(const FILETIME *lpftLocal, LPFILETIME lpft);
BOOL WINAPI FileTimeToSystemTime(const FILETIME *lpft, LPSYSTEMTIME lpst);
BOOL WINAPI SystemTimeToFileTime(const SYSTEMTIME *lpst, LPFILETIME lpft);
BOOL WINAPI FileTimeToLocalFileTime(const FILETIME *lpft, LPFILETIME lpftLocal);
BOOL WINAPI LocalFileTimeToFileTime(const FILETIME *lpftLocal, LPFILETIME lpft);
那么,如果
使用FILETIME来记录时间,需要加上n秒,如何进行累加计算呢?
#define PER_SECOND 1*10*1000*1000 //1秒
ULONGLONG ullSeconds = n* PER_SECOND;
FILETIME tTime;
ULARGE_INTEGER temp;
temp.QuadPart = ullSeconds;
tTime.dwHighDateTime = temp.HighPart;
tTime.dwLowDateTime = temp.LowPart;
temp.QuadPart = ullSeconds;
tTime.dwHighDateTime = temp.HighPart;
tTime.dwLowDateTime = temp.LowPart;
依次类推,1小时就是36000000000;1天就是864000000000
说明:ULARGE_INTEGER 的结构定义如下
typedef union _ULARGE_INTEGER {
struct {
DWORD LowPart;
DWORD HighPart;
};
struct {
DWORD LowPart;
DWORD HighPart;
} u;
#endif //MIDL_PASS
ULONGLONG QuadPart;
} ULARGE_INTEGER;
struct {
DWORD LowPart;
DWORD HighPart;
};
struct {
DWORD LowPart;
DWORD HighPart;
} u;
#endif //MIDL_PASS
ULONGLONG QuadPart;
} ULARGE_INTEGER;
typedef ULARGE_INTEGER *PULARGE_INTEGER;
可以看到,它是一个64位的联合体,它的空间大小就是64位,当使用QuadPart时等于是以64位的整体来使用的;
而若使用 LowPart和 HighPart时,等于是以高低32位来使用的。
因此,temp.QuadPart = ullSeconds;是给QuadPart赋值,实际上也就是给temp的内存空间赋值了,当然也可以通过LowPart和HighPart分别取出temp的低32位和高32位了。