Solved

Change system time zone

Posted on 2004-04-20
3
1,402 Views
Last Modified: 2008-02-01
Hi experts,

Is there any EASY way to change Windows' time zone through the registry?  I found the registry key with the time zone information...
"HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation"
but it doesn't seem to be easy to manipulate, because of all the names, etc... that also need to be set when changing the time zone (not only the bias).

Is it easier to use the SetTimeZoneInformation WinAPI call to change the system's time zone?  Can anyone give me some sample code on how to change the date, time, and time zone using this function?

Thanks,
dannyguindi
0
Comment
Question by:dannyguindi
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
mokule earned 50 total points
ID: 10873003
Hi
Look there
http://17slon.com/gp/gp/gptimezone.htm
and there
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/settimezoneinformation.asp

and here how You can use the function

var
  tz: _TIME_ZONE_INFORMATION;
begin

GetTimeZoneInformation(tz); // to check current settings

// UTC = local time + bias + standard bias
// or
// UTC = local time + bias + daylight bias

tz.Bias := -60;

FillChar(tz.StandardName,sizeof(tz.StandardName),#0);
// can set any string
StringToWideChar('Standard Time',tz.StandardName,sizeof(tz.StandardName));
tz.StandardDate.wYear := 0;
tz.StandardDate.wMonth := 10;    // October
tz.StandardDate.wDayOfWeek := 0; // sunday
tz.StandardDate.wDay := 5;      // means last week of month
tz.StandardDate.wHour := 3;
tz.StandardDate.wMinute := 0;
tz.StandardDate.wSecond := 0;
tz.StandardDate.wMilliseconds := 0;
tz.StandardBias := 0;

FillChar(tz.DaylightName,sizeof(tz.DaylightName),#0);
StringToWideChar('Summer Time',tz.DaylightName,sizeof(tz.DaylightName));
tz.DaylightDate.wYear := 0;
tz.DaylightDate.wMonth := 3;     // March
tz.DaylightDate.wDayOfWeek := 0; // sunday
tz.DaylightDate.wDay := 5;      // last week of month
tz.DaylightDate.wHour := 2;
tz.DaylightDate.wMinute := 0;
tz.DaylightDate.wSecond := 0;
tz.DaylightDate.wMilliseconds := 0;
tz.DaylightBias := -60;

SetTimeZoneInformation(tz);
0
 

Author Comment

by:dannyguindi
ID: 10893818
Just what I needed.  Many thanks.
0
 
LVL 17

Expert Comment

by:mokule
ID: 10894041
I'm happy to help :)

Marek
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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

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

16 Experts available now in Live!

Get 1:1 Help Now