Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2008-08

Convert time to GMT

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

amir

Hi!

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?

Amir

Reply by email

Graeme Geldenhuys
to amir
amir wrote 9 lines
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/

Reply by email