在vc中实现time_t和SYSTEMTIME 与delphi中的TDateTime的转换。
delphi中的TDateTime其实就是一个double型。
TDateTime TimetToDateTime(time_t t)
{
double result=(double)t / 86400.0 + 25569;
return TDateTime(result);
}
time_t DateTimeToTimet(TDateTime dt)
{
return time_t((dt-25569) * 86400.0);
}
void DateTimeToSystemTime(TDateTime dt, LPSYSTEMTIME pst)
{
double t= (dt-25569) * 86400.0;
FILETIME ft;
LONGLONG ll = LONGLONG((t* 10000000) + 116444736000000000);
ft.dwLowDateTime = (DWORD) ll;
ft.dwHighDateTime = (DWORD)(ll >> 32);
FileTimeToSystemTime( &ft, pst );
}
TDateTime SystemTimeToDateTime(SYSTEMTIME st)
{
FILETIME ft;
SystemTimeToFileTime( &st, &ft );
LONGLONG ll;
ULARGE_INTEGER ui;
ui.LowPart = ft.dwLowDateTime;
ui.HighPart = ft.dwHighDateTime;
ll = ft.dwHighDateTime;
ll = (ll<<32) + ft.dwLowDateTime;
TDateTime result =25569+(LONGLONG)(ui.QuadPart - 116444736000000000) / 864000000000.0;
return result;
}
原文:
http://blog.csdn.net/constantine/archive/2008/12/25/3607513.aspx