Solved

GMT versus LocalTimeZone

Posted on 2002-06-26
2
295 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 55
Delphi - replicating a form 8 64
Delphi XE10 Round Image 2 77
Installshield for Embarcadero EX 10.1 Berlin 4 18
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

912 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now