Solved

GMT versus LocalTimeZone

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

10 Experts available now in Live!

Get 1:1 Help Now