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相互转换#####
#####SYSTEMTIME 与 FILETIME相互转换#####
可以使用系统函数
FileTimeToSystemTime(&ftcreate,&stcreate);
参数:
(lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME)
说明
根据一个FILETIME结构的内容,装载一个SYSTEMTIME结构
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpFileTime FILETIME,包含了文件时间的一个结构
lpSystemTime SYSTEMTIME,用于装载系统时间信息的一个结构
#####SYSTEMTIME 与 time_t相互转换#####
void TimetToSystemTime(
time_t t, LPSYSTEMTIME pst )
{
FILETIME ft;
void FileTimeToTime_t( FILETIME ft, time_t *t )
{
LONGLONG ll;
ULARGE_INTEGER ui;
ui.LowPart = ft.dwLowDateTime;
ui.HighPart = ft.dwHighDateTime;
ll = ft.dwHighDateTime << 32 + ft.dwLowDateTime;
*t = ((LONGLONG)(ui.QuadPart - 116444736000000000) / 10000000);
}
{
FILETIME ft;
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);
}
void FileTimeToTime_t( FILETIME ft, time_t *t )
{
LONGLONG ll;
ULARGE_INTEGER ui;
ui.LowPart = ft.dwLowDateTime;
ui.HighPart = ft.dwHighDateTime;
ll = ft.dwHighDateTime << 32 + ft.dwLowDateTime;
*t = ((LONGLONG)(ui.QuadPart - 116444736000000000) / 10000000);
}