To covert local time to GMT and vice versa you can use the bellow functions.
function fetchGMTBias: Integer;
var
TZinfo: TTimeZoneInformation;
Mode: DWord;
begin
Mode := GetTimeZoneInformation(TZinfo);
Result := TZinfo.Bias;
case Mode of
TIME_ZONE_ID_INVALID:
RaiseLastOSError;
TIME_ZONE_ID_STANDARD:
Result := Result +TZinfo.StandardBias;
TIME_ZONE_ID_DAYLIGHT:
Result := Result + TZinfo.DaylightBias;
end;
end;
function LocaleToGMT(const aValue: TDateTime): TDateTime;
begin
Result := aValue + (fetchGMTBias / (24*60));
end;
function GMTToLocale(const aValue: TDateTime): TDateTime;
begin
Result := aValue - (fetchGMTBias / (24*60));
end;
function fetchGMTBias: Integer;
var
TZinfo: TTimeZoneInformation;
Mode: DWord;
begin
Mode := GetTimeZoneInformation(TZinfo);
Result := TZinfo.Bias;
case Mode of
TIME_ZONE_ID_INVALID:
RaiseLastOSError;
TIME_ZONE_ID_STANDARD:
Result := Result +TZinfo.StandardBias;
TIME_ZONE_ID_DAYLIGHT:
Result := Result + TZinfo.DaylightBias;
end;
end;
function LocaleToGMT(const aValue: TDateTime): TDateTime;
begin
Result := aValue + (fetchGMTBias / (24*60));
end;
function GMTToLocale(const aValue: TDateTime): TDateTime;
begin
Result := aValue - (fetchGMTBias / (24*60));
end;
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου