Question : Convert time from EST to localtime

Hi,

I've found this function: SystemTimeToTzSpecificLocalTime to be used to convert time from other timezone to your local time.

The problem is i'd like to convert time from EST to my local time and I don't know how to fill the lpTimeZoneInformation parameter. I've seen in an example it was nil when converting from UTC to localtime.

Does anybody know how to fill this parameter?

Answer : Convert time from EST to localtime

You can simply use the same function adding the hours difference between EST and UTC

Let's say that EST is UTC less 5 then you could use something like this

Uses
DateUtils;

{add a TDateTimePicker to the form}

procedure TForm1.Button1Click(Sender: TObject);
var
  ESTTime: TDateTime;
  function ESTToSystemTime(EST: TDateTime): TDateTime;
  var
    TimeZoneInf: _TIME_ZONE_INFORMATION;
    ESTTime, LocalTime: TSystemTime;
  begin
    EST := IncHour(EST, -5);
    if GetTimeZoneInformation(TimeZoneInf) < $FFFFFFFF then
    begin
      DatetimetoSystemTime(EST, ESTTime);
      if SystemTimeToTzSpecificLocalTime(@TimeZoneInf, ESTTime, LocalTime) then
      begin
        result := SystemTimeToDateTime(LocalTime);
      end
      else
        result := EST;
    end
    else
      result := EST;
  end;

begin
  ESTTime := ESTToSystemTime(DateTimePicker1.DateTime);
end;
Random Solutions  
 
programming4us programming4us