Solved

GMT versus LocalTimeZone

Posted on 2002-06-26
2
323 Views
Last Modified: 2010-04-04
Hi,

I need some help with the following questions

How to convert from
   1) GMT to LocalTime
   2) LocalTime to GMT

E.g.  during the summer, the local time in Brussels
is GMT + 2, during the winter it is GMT + 1
-->  17:20 hour in Brussels (during the summer) is the same as 15:20 GMT

I would like some sample code showing me the time in the different timezones (like example above)

best regards,

Daniel
0
Comment
Question by:KinnaerD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 8

Expert Comment

by:Cesario
ID: 7111710
function UTCOffset: Single;

var
  TZI: TTimeZoneInformation;

begin
  GetTimeZoneInformation(TZI);
  Result := TZI.Bias / 60 / 24;
end;

function LocalDateTimeToUTC(const LocalDateTime: TDateTime): TDateTime;

begin
  Result := LocalDateTime + UTCOffset;
end;

function UTCToLocalDateTime(const UTC: TDateTime): TDateTime;

begin
  Result := UTC - UTCOffset;
end;

best regards

Cesario
0
 
LVL 8

Accepted Solution

by:
Cesario earned 200 total points
ID: 7111725
uuups please change this function:

// GetTimeZoneBias
function UTCOffset: TDateTime;
var
  TZI: TTimeZoneInformation;
begin
  case GetTimeZoneInformation(TZI) of
    TIME_ZONE_ID_STANDARD : Result := (TZI.Bias + TZI.StandardBias) / 1440;
    TIME_ZONE_ID_DAYLIGHT : Result := (TZI.Bias + TZI.DaylightBias) / 1440;
    TIME_ZONE_ID_UNKNOWN  : Result := TZI.Bias / 1440;
  else
    RaiseLastWin32Error;
  end;
end;


Best Regards

Cesario
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question