首页  编辑  

获取当前用户的时区与GMT的差

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

function GetTimeZoneDelta: TDateTime;

var

 TzInfo: TTimeZoneInformation;

begin

 case GetTimeZoneInformation(TzInfo) of

   TIME_ZONE_ID_UNKNOWN: Result := TzInfo.Bias / 1440;

   TIME_ZONE_ID_STANDARD: Result := (TzInfo.Bias + TzInfo.StandardBias) /

1440;

   TIME_ZONE_ID_DAYLIGHT: Result := (TzInfo.Bias + TzInfo.DayLightBias) /

1440;

 else

   RaiseLastWin32Error;

 end;

end;

function CurGmtToLocalMinutesOffset: integer;

var t1,g2,t3: tDateTime;

begin

 t3 := Now;

 Repeat

   t1 := t3;

   g2 := CurGmt;

   t3 := Now;

 Until abs(t1-t3) < 1/24/60/4;

 Result := round((t3-g2)*24*60);

end;

function CurGMT: TDateTime;

var TimeRec: TSystemTime;

begin

 GetSystemTime(TimeRec);

 Result := SystemTimeToDateTime(TimeRec);

end;