[fpc-devel] Convert time to GMT
Graeme Geldenhuys
graemeg.lists at gmail.com
Thu Aug 14 09:49:31 CEST 2008
On 8/14/08, amir <amir at aavani.net> wrote:
> I want to have the date/time of my computer for GMT. As I searched the
> rtl.pdf, I found out that there are some functions
> in OLDLinux unit which return the current time for GMT (not local
> timezone). I wonder if they can be used on Windows (It said
> that those functions return the current kernel time which is in GMT).
>
> I also found two functions for reading the local timezone but they are
> located in Unix and OLDUnix units. Do they have an implementation
> on Windows?
With complements from the tiOPF project. ;-)
{$IFDEF MSWINDOWS}
function tiGMTOffset: TDateTime;
var
TZI: TTimeZoneInformation;
begin
Result := 0; // Removes 'return value might be undefined' warning.
case GetTimeZoneInformation(TZI) of
TIME_ZONE_ID_STANDARD: Result := (TZI.Bias + TZI.StandardBias) *
cdtOneMinute;
TIME_ZONE_ID_DAYLIGHT: Result := (TZI.Bias + TZI.DaylightBias) *
cdtOneMinute;
TIME_ZONE_ID_UNKNOWN: Result := TZI.Bias * cdtOneMinute;
else
RaiseLastWin32Error;
end;
end;
function tiLocalTimeToGMT(const ALocalTime: TDateTime): TDateTime;
begin
Result := ALocalTime + tiGMTOffset;
end;
function tiGMTToLocalTime(const AGMTTime: TDateTime): TDateTime;
begin
Result := AGMTTime - tiGMTOffset;
end;
{$ENDIF}
Regards,
- Graeme -
_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
More information about the fpc-devel
mailing list