Introduction
This program demonstrates how to change the Windows time zone information programmatically.
Background
I have seen very little information on the internet on how to change the Windows time zone information programmatically with C++. This article will show you how.
There is a list of all the time zones that are available. This is available in the registry, under _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"). However, there is no data structure that works with the existing TZI binary value in the reg key.
Here is the Eastern Standard Time TZI Reg Binary Data IE:
Here is the total set of bytes:
2C 01 00 00 00 00 00 00
C4 FF FF FF 00 00 0A 00
00 00 05 00 02 00 00 00
00 00 00 00 00 00 04 00
00 00 01 00 02 00 00 00
00 00 00 00
Let's decipher what this is...
(little-endian) => (big-endian)
2C 01 00 00 => 00 00 01 2C = 300 Bias
00 00 00 00 => 00 00 00 00 = 0 Std Bias
C4 FF FF FF => FF FF FF C4 = 4294967236 Dlt Bias
( SYSTEM TIME ) StandardDate
00 00 => 00 00 = Year
0A 00 => 00 0A = Month
00 00 => 00 00 = Day of Week
05 00 => 00 05 = Day
02 00 => 00 02 = Hour
00 00 => 00 00 = Minutes
00 00 => 00 00 = Seconds
00 00 => 00 00 = Milliseconds
( SYSTEM TIME ) DaylightDate
00 00 => 00 00 = Year
04 00 => 00 04 = Month
00 00 => 00 00 = Day of Week
01 00 => 00 01 = Day
02 00 => 00 02 = Hour
00 00 => 00 00 = Minutes
00 00 => 00 00 = Seconds
00 00 => 00 00 = Milliseconds
If you notice, it represents the TIME_ZONE_INFO
structure.
struct TIME_ZONE_INFO
{
ULONG Bias;
ULONG StandardBias;
ULONG DaylightBias;
SYSTEMTIME StandardDate;
SYSTEMTIME DaylightDate;
};
Using the code
Below, you will find the source in text form.
History
- Feb 2, 2006 - Fixed a major typo with regards to the
TimeZoneInfoToTimeZoneInformation
function.
- Feb 9, 2005 - Cleaned up the code and made it more readable.