SYSTEMTIME与__int64的相互转换

1. SYSTEMTIME转__int64

__int64 SystemTimeToInt64(const SYSTEMTIME& itime) { FILETIME ft; SystemTimeToFileTime(&itime, &ft); ULARGE_INTEGER ularge; ularge.LowPart = ft.dwLowDateTime; ularge.HighPart = ft.dwHighDateTime; __int64 int64 = ularge.QuadPart; return int64; }

 

2. __int64转SYSTEMTIME

SYSTEMTIME Int64ToSystemTime(const __int64& itime) { FILETIME ft; SYSTEMTIME st; ULARGE_INTEGER ularge; __int64 tmptimeA, tmptimeB; tmptimeA = itime; tmptimeB = itime; ularge.HighPart = (DWORD)(tmptimeA>>32); ularge.LowPart = (DWORD)((tmptimeB<<32)>>32); ft.dwLowDateTime = ularge.LowPart; ft.dwHighDateTime = ularge.HighPart; FileTimeToSystemTime(&ft, &st); return st; }

 

3. 使用例子

SYSTEMTIME timeA, timeB; GetSystemTime(&timeA); printf("当前时间:%d-%d-%d %d:%d:%d/n", timeA.wYear, timeA.wMonth, timeA.wDay, timeA.wHour, timeA.wMinute, timeA.wSecond); __int64 itime = SystemTimeToInt64(timeA); printf("当前时间:%lld/n", itime); timeB = Int64ToSystemTime(itime); printf("当前时间:%d-%d-%d %d:%d:%d/n", timeB.wYear, timeB.wMonth, timeB.wDay, timeB.wHour, timeB.wMinute, timeB.wSecond);

你可能感兴趣的:(Integer)