首页  编辑  

GMT时间转换

Tags: /超级猛料/Date.Time.时间和日期/   Date Created:

GMT时间转换

const

 MinsPerDay = 24*60;

function GetGMTBias : Integer;

var

 info: TTimeZoneInformation;

 Mode: DWord;

begin

 Mode := GetTimeZoneInformation(info);

 Result := info.Bias;

 case Mode of

   TIME_ZONE_ID_INVALID:

   begin

     RaiseLastWin32Error

   end;

   TIME_ZONE_ID_STANDARD:

   begin

     Result := Result+info.StandardBias

   end;

   TIME_ZONE_ID_DAYLIGHT:

   begin

     Result := Result+info.DaylightBias

   end;

 end;

end;

function LocaleDateTimeToGMTDateTime(const Value: TDateTime) : TDateTime;

begin

 Result := Value+(GetGMTBias/MinsPerDay);

end;

function GMTDateTimeToLocaleDateTime(const Value: TDateTime) : TDateTime;

begin

 Result := Value-(GetGMTBias/MinsPerDay);

end;

The Delphi Magazine Sample Article.mht (163.6KB)