unit TimeUtils;
interface
function NowUTC: TDateTime;
function DateUTC: TDateTime;
function TimeUTC: TDateTime;
function GetTimeZoneBias:TDateTime;
implementation
uses Windows, SysUtils;
// liefert die aktuelle Systemzeit in Coordinated Universal Time (UTC)
function NowUTC: TDateTime;
var
SystemTime: TSystemTime;
begin
GetSystemTime(SystemTime);
with SystemTime
do
Result := EncodeDate(wYear, wMonth, wDay) +
EncodeTime(wHour, wMinute, wSecond, wMilliseconds);
end;
function DateUTC: TDateTime;
begin
Result := Int(NowUTC);
end;
function TimeUTC: TDateTime;
begin
Result := Frac(NowUTC);
end;
// liefert den Abstand der lokalen Zeit zu UTC
// UTC = lokaleZeit + GetTimeZoneBias
function GetTimeZoneBias:TDateTime;
const
MINUTES_PER_DAY = 24.0 * 60.0;
var
tzi : TTimeZoneInformation;
begin
case GetTimeZoneInformation(tzi)
of
TIME_ZONE_ID_STANDARD:
result := (tzi.Bias) / MINUTES_PER_DAY;
TIME_ZONE_ID_DAYLIGHT:
// Sommerzeit
Result := (tzi.Bias+tzi.DaylightBias) / MINUTES_PER_DAY;
else
Result := 0.0;
end;
end;
end.