BPSoftware.com
Home   Utilities   Purchase   FAQ   Support   Contact        
Shareware Utilities
 APrintDirect
 AIconExtract
 AFile Attribute Manager
Freeware Utilities
 AddrMon
 AFileSync
 ASysIcon
 B&P Table Utilities
 BPACLer
 BPSNMPMon
 BPSNMPUtil
 CharCount
 Delphi® Components
 MacAddr
Miscellaneous
 BPSoftware Blog
 Purchase Shareware
 Support

 Subscribe!

Tuesday, January 17, 2006
Where in the world?

When dealing with individuals in different time zones it is not always easy to keep track of ‘their’ local time. Many know the time zone bias for the popular world time zones but what about those not so well known places? In an effort to prevent the need to do some quick calculations I decided I’d write a little utility (desktop clock that will be added to the Freeware section someday soon) to display multiple time zone times. Question:With the idea in mind, how does one get a list of time zones and calculate the bias?

Answer: MSDN is your friend! I found a nice article on Retrieving Time-Zone Information. The article explains where and how the time zone information is stored. The TIME_ZONE_INFORMATION structure contains a Bias, StandardBias and DaylightBias to assist in the calculating of the time in a selected time zone.

For the following quick code I had placed a TComboBox and a TMemo on a TForm. When the form is shown the available time zones are added to the TComoBox.Items. When a time zone is selected pieces of information are displayed in the TMemo. For this I used BDS2006.

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Memo1: TMemo;
procedure ComboBox1Change(Sender: TObject);
procedure FormShow(Sender: TObject);
public
procedure FillComboBox(combobox: TComboBox);
procedure FillMemo(timezone: string; memo: TMemo);
end;

var
Form1: TForm1;

implementation

uses
Registry;
{$R *.dfm}

{ TForm1 }

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if Sender is TComboBox then
FillMemo(TComboBox(Sender).Text,Memo1);
end;

procedure TForm1.FillComboBox(combobox: TComboBox);
var
reg: TRegistry;
begin
reg:= TRegistry.Create(KEY_READ);
combobox.Items.BeginUpdate;
try
comboBox.Items.Clear;
reg.RootKey:= HKEY_LOCAL_MACHINE;
if reg.OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones',False) then
reg.GetKeyNames(combobox.Items);
finally
reg.Free;
combobox.Items.EndUpdate;
end;
end;


procedure TForm1.FillMemo(timezone: string; memo: TMemo);
var
reg: TRegistry;
regkey: string;
tzi: TTimeZoneInformation;
begin
memo.Lines.Clear;
reg:= TRegistry.Create(KEY_READ);
regkey:= Format('SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\%s',[timezone]);
try
reg.RootKey:= HKEY_LOCAL_MACHINE;
if reg.OpenKey(regkey,False) then
begin
memo.Lines.Add(Format('Daylight Time Display: %s',[reg.ReadString('Dlt')]));
memo.Lines.Add(Format('Standard Time Display: %s',[reg.ReadString('Std')]));
reg.ReadBinaryData('TZI',tzi,sizeof(tzi));
memo.Lines.Add(Format('Bias: %d minutes',[tzi.Bias]));
end;
finally
reg.Free;
end;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
FillComboBox(ComboBox1);
end;

end.

Labels: , ,

posted by Brad Prendergast at 6:45:00 AM
Comments:
Links to this post:

Create a Link

Recent Posts
 Remember SWAG?
 Express
 Adieu George!
 Is it better to be tall or short?
 Syncing
 Piecing it all together (Part 3)
 Piecing it all together (Part 2)
 Piecing it all together (Part 1)
 Some Component Updates
 Geeky Thought

 Subscribe!


Labels



Archives
 October 2005
 November 2005
 December 2005
 January 2006
 February 2006
 March 2006
 April 2006
 May 2006
 June 2006
 July 2006
 August 2006
 September 2006
 December 2006
 January 2007
 February 2007
 March 2007
 September 2007
 October 2007
 November 2007
 July 2008
 November 2008
Powered by Blogger