注意:
如果使用struct tm 通过 localtime和mktime做转换,需注意时区的问题!!!!!!
第一个
void TimetToSystemTime( time_t t, LPSYSTEMTIME pst )
{
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);
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/modena/archive/2005/01/13/251653.aspx
第二个
#####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;
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);
}
#### FileTimeToTime_t ####
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);
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zjnig711/archive/2008/04/15/2294151.aspx
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zjnig711/archive/2008/04/15/2294151.aspx