Τετάρτη 8 Μαΐου 2013

GMT Time To Local Time and vice versa

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;

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου