不同timestamp的转换
在程序开发过程中不断会碰到不同timestamp的转换,在这里做一个总结:
一.时间类型间的转换:
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);
一.时间类型间的转换:
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);