Solved

GMT versus LocalTimeZone

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 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