It is not recommended that you add and subtract values from the SYSTEMTIME structure to obtain relative times. Instead, you should Convert the SYSTEMTIME structure to a FILETIME structure. Copy the resulting FILETIME structure to a ULARGE_INTEGER structure. 按照MSDN的说法,你可以把 SYSTEMTIME 变量转换为 FILETIME 类型,然后把 FILETIME 转换为 ULARGE_INTEGER 类型,我们知道 ULARGE_INTEGER 是无符号大整数,可以直接用来进行数学运算,下面就简单了。
Copy the resulting FILETIME structure to a ULARGE_INTEGER structure. 按照MSDN的说法,你可以把 SYSTEMTIME 变量转换为 FILETIME 类型,然后把 FILETIME 转换为 ULARGE_INTEGER 类型,我们知道 ULARGE_INTEGER 是无符号大整数,可以直接用来进行数学运算,下面就简单了。
然后计算出时间差。
struct tm tmCreate;
memset((void*)&tmCreate,0,sizeof(tm));
tmCreate.tm_year=screateTime.wYear;//2004
tmCreate.tm_mon=screateTime.wMonth;//11
tmCreate.tm_mday=screateTime.wDay;//8
tmCreate.tm_hour=screateTime.wHour;//12
tmCreate.tm_min=screateTime.wMinute;//18 time_t ttCreate;
ttCreate=mktime(&tmCreate);但是上面的mktime()返回-1,这是为什么呀?
然后计算FILETIME之差,FILETIME的精度是100ns,FILETIME实际上也可以看着一个__int64.