一、時間表示法
1.FILETIME
typedef struct STRUCT tagFILETIME { DWORD dwLowDateTime; DWORD dwHighDateTime;} FILETIME;
FILETIME是一個無符號整數,表示自1601年1月1日起,以100納秒爲單位,所經歷的時間。
CoFileTimeNow可以取得當前的FILETIME。
2.DosDateTime(DOSTIME)
typedef tagDosDateTime {WORDDosDate, WORD DosTime} DosDateTime;
MS-DOS records file dates and timesas packed 16-bit values. An MS-DOS date has the following format:
Bits
Contents
0-4
Days of the month (1-31).
5-8
Months (1 = January, 2 = February, and so forth).
9-15
Year offset from 1980 (add 1980 to get actual year).
An MS-DOS time has the followingformat:
Bits
Contents
0-4
Seconds divided by 2.
5-10
Minutes (0-59).
11-15
Hours (0-23 on a 24-hour clock).
3. SYSTEMTIME
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME;
GetSystemTime、GetLocalTime可以取得當前的SYSTEMTIME。
4.VariantTime(DATE)
就是double,也即Windows數據類型DATE,COleDateTime是對DATE的包裝。1899年12月30日【不是31日】用0.0表示,1.25表示1899年12月31日6點鐘。負數表示1899年12月30日之前的時間。表示範圍:100年1月1日到9999年12月31日。
5.time_t、__time32_t、__time64_t
這是C運行庫使用的時間表示,CTime是對它的包裝,提供了到其他時間表示的轉換。time_t是一個無符號整數,表示自1970年1月1日起,以1秒爲單位,所經歷的時間。
struct timeb {
time_t time;
unsigned short millitm;//毫秒數
short timezone;
short dstflag;
};
6.tm
C運行庫定義在time.h中;Windows Driver Kit定義在hbaapi.h
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
二、獲得時間的方法
void GetSystemTime(LPSYSTEMTIME lpSystemTime); //用該方法獲得的時間是格林威治時間(UTC時間),而不是當前計算機右下角的時間。
void GetLocalTime(LPSYSTEMTIME lpSystemTime); //該方法獲得的是本地時間。
void GetSystemTimeAsFileTime(LPFILETIME lpFileTime); //該方法或的的也是格林威治時間。
GetThreadTimes(): //獲得線程時間,就不註解了
DWORD GetTickCount(void); //這是獲得機器啓動後的計時時間,也是按毫秒計時的。
三、各種時間表示法之間的轉換函數
CoFileTimeToDosDateTime
CoDosDateTimeToFileTime
FileTimeToDosDateTime
DosDateTimeToFileTime
SystemTimeToFileTime
FileTimeToSystemTime
FileTimeToLocalFileTime
LocalFileTimeToFileTime
SystemTimeToVariantTime
VariantTimeToSystemTime
VariantTimeToDosDateTime
DosDateTimeToVariantTime
在前4種表示法中,只有SystemTime和DosDateTime之間,Variant和FileTime之間缺乏之間轉換。