Solved

Change system time zone

Posted on 2004-04-20
3
1,392 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

15 Experts available now in Live!

Get 1:1 Help Now