都是从网上转载过来的,总结一下。
(1) FILETIME和64位整型运算
一个简单应用记录一下取系统当前时间,转化为FILETIME格式,再转化成毫秒数其中FILETIME::QuartPart 为ULONGLONG(即unsigned __int64)类型,64位整数
FILETIME ft;
ULARGE_INTEGER uliTime;
//SYSTEMTIME st;
//GetSystemTime(&st);
//SystemTimeToFileTime(&st, &ft);
GetSystemTimeAsFileTime(&ft); //win32 api
uliTime.LowPart = ft.dwLowDateTime;
uliTime.HighPart = ft.dwHighDateTime;
ulitime.QuartPart /= 10000; //转化为毫秒数,因为FILETIME精度为100纳秒
(2)FILETIME, SYSTEMTIME 与 time_t 相互转换
#####SYSTEMTIME 与 FILETIME相互转换#####
可以使用系统函数
FileTimeToSystemTime(&ftcreate,&stcreate);
参数:
(lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME)
说明
根据一个FILETIME结构的内容,装载一个SYSTEMTIME结构
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpFileTime FILETIME,包含了文件时间的一个结构
lpSystemTime SYSTEMTIME,用于装载系统时间信息的一个结构
#####SYSTEMTIME 与 time_t相互转换#####
LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
ft.dwLowDateTime = (DWORD) ll;
ft.dwHighDateTime = (DWORD)(ll >> 32);
FileTimeToSystemTime( &ft, pst );
}
void SystemTimeToTimet( SYSTEMTIME st, time_t *pt )
{
FILETIME ft;
SystemTimeToFileTime( &st, &ft );
LONGLONG ll;
ULARGE_INTEGER ui;
ui.LowPart = ft.dwLowDateTime;
ui.HighPart = ft.dwHighDateTime;
ll = (ft.dwHighDateTime << 32) + ft.dwLowDateTime;
*pt = (DWORD)((LONGLONG)(ui.QuadPart - 116444736000000000) / 10000000);
}
一.时间类型间的转换:
1.time_t 转 FILETIME
FILETIME ft;
LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
ft.dwLowDateTime = (DWORD) ll;
ft.dwHighDateTime = (DWORD)(ll >> 32);
2.FILETIME 转 time_t
FILETIME ft;
LONGLONG llTime;
time_t t;
llTime = (ft.dwHighDateTime << 32) + ft.dwLowDateTime;
t = (DWORD)((LONGLONG)(llTime - 116444736000000000) / 10000000);
3.SYSTEMTIME 转 FILETIME
FILETIME ft;
SYSTEMTIME st;
SystemTimeToFileTime( &st, &ft );
4. FILETIME 转 SYSTEMTIME
FILETIME ft;
SYSTEMTIME st;
FileTimeToSystemTime( &ft, &st);
5.DATE 转 SYSTEMTIME
DATE pst;
SYSTEMTIME st;
VariantTimeToSystemTime(pst,&st);
6. SYSTEMTIME 转 DATE
DATE pst;
SYSTEMTIME st;
SystemTimeToVariantTime(st, &pst);
7. BYTE转DWORD
#define MAKEB2W(c0, c1, c2, c3) ((DWORD)(((BYTE)(c0)|((WORD)((BYTE)(c1))<<8))|(((DWORD)(BYTE)(c2))<<16) | (((DWORD)(BYTE)(c3))<<24)))