Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
Difference between time zones
1 comments. Current rating: (1 votes). Leave comments and/ or rate it.
To calculate the difference between two timezones e.g. between your computer's local time and Greenwich Mean Time (GMT) you can use GetTimeZoneInformation.
There are two ways to convert a TDateTime value between local time and GMT:
GetTimeZoneInformation and LocalFileTimeToFileTime.
The code below bases on GetTimeZoneInformation.  | |  | | unit TimeZoneConversion;
interface
uses
Windows, SysUtils;
function LocaleDateTimeToGMTDateTime(const Value: TDateTime) : TDateTime;
function GMTDateTimeToLocaleDateTime(const Value: TDateTime) : TDateTime;
implementation
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;
end. | |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|