11
июня
2007
Функция перевода SYSTEMTIME в TDateTime
Данная функция переводит тип данных SYSTEMTIME в TDateTime:
function SystemTime2DateTime(const SystemTime : TSystemTime; var DateTime : TDateTime ) : Boolean;
var I : Integer;
_Day : Integer;
DayTable: PDayTable;
begin
Result := False;
DateTime := 0.0;
DayTable := @MonthDays[IsLeapYear(SystemTime.wYear)];
with SystemTime do
if {(wYear >= 0) !always true! and} (wYear <= 9999) and
{(wMonth >= 1) and !otherwise can not convert time only!}
(wMonth <= 12) and
{(wDay >= 1) and !otherwise can not convert time only!}
(wDay <= DayTable^[wMonth]) and //
(wHour < 24) and (wMinute < 60) and (wSecond < 60) and (wMilliSeconds < 1000) then //
begin
_Day := wDay;
for I := 1 to wMonth - 1 do
Inc(_Day, DayTable^[I]);
I := wYear - 1;
//--------------- by Vadim Petrov ------++
if I<0 then i := 0; //
//--------------------------------------++
DateTime := I * 365 + I div 4 - I div 100 + I div 400 + _Day
+ (wHour * 3600000 + wMinute * 60000 + wSecond * 1000 + wMilliSeconds) / MSecsPerDay;
Result := True;
end;
end;
var I : Integer;
_Day : Integer;
DayTable: PDayTable;
begin
Result := False;
DateTime := 0.0;
DayTable := @MonthDays[IsLeapYear(SystemTime.wYear)];
with SystemTime do
if {(wYear >= 0) !always true! and} (wYear <= 9999) and
{(wMonth >= 1) and !otherwise can not convert time only!}
(wMonth <= 12) and
{(wDay >= 1) and !otherwise can not convert time only!}
(wDay <= DayTable^[wMonth]) and //
(wHour < 24) and (wMinute < 60) and (wSecond < 60) and (wMilliSeconds < 1000) then //
begin
_Day := wDay;
for I := 1 to wMonth - 1 do
Inc(_Day, DayTable^[I]);
I := wYear - 1;
//--------------- by Vadim Petrov ------++
if I<0 then i := 0; //
//--------------------------------------++
DateTime := I * 365 + I div 4 - I div 100 + I div 400 + _Day
+ (wHour * 3600000 + wMinute * 60000 + wSecond * 1000 + wMilliSeconds) / MSecsPerDay;
Result := True;
end;
end;
Категория Дата и время, Delphi | 0 Comments
Версия для печати