Yesterday I got looped into a call where a customer that reported that meeting requests were ahead by an hour when he sent them to the Internet. Knowing this had to have something to do with Timezones and DST, I whipped together a quick tool to Display UTC time, Local time, and some other time zone information.
We can always verify what’s in the Windows Time Zone Database using TZEdit but not information on the current time zone. You could also pull this from the registry HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\TimeZoneInformation if you know how to interpret the data, but this makes it much easier. But in addition to all this, I would’ve never figured out this issue without the UTC display from this tool.
In the customer’s case, the UTC time showed he was an hour ahead of the rest of the world in his domain but because he had hacked up his timezone information to display the local time correctly, he had no idea his UTC time was wrong.
Here is some sample output:
UTC System Time: 9/5/2007 21:47
Local System Time: 9/5/2007 17:47
Operating in DAYLIGHT time
Time Zone Name: Eastern Daylight Time
Daylight Bias: -60 Minutes (or -1 Hours)
Standard: Occurs first Sunday of November at 2: 0
Daylight: Occurs second Sunday of March at 2: 0
Bias: 300 Minutes (or 5 Hours)
For anyone who’s interested, here is the source of the main function. It demonstrates the use of the GetSystemTime, SystemTimeToTzSpecificLocalTime, and GetTimeZoneInformation functions.
int _tmain(int argc, _TCHAR* argv)
// Apparently this function cannot fail – no need to check error case
L“UTC System Time: %i/%i/%i %i:%i\r\n”,
BOOL fResult = SystemTimeToTzSpecificLocalTime(
NULL, // current timezone
&utctime, // input time
&localtime // output time
L“Local System Time: %i/%i/%i %i:%i\r\n”,
DWORD dwResult = GetTimeZoneInformation(&tzInfo);
wprintf(L“Operating in UNKNOWN time\r\n”);
wprintf(L“Operating in STANDARD time\r\n”);
wprintf(L“Time Zone Name: %s \r\n”, tzInfo.StandardName);
wprintf(L“Standard Bias: %i Minutes (or %i Hours) \r\n”, tzInfo.StandardBias, tzInfo.StandardBias / 60);
wprintf(L“Operating in DAYLIGHT time\r\n”);
wprintf(L“Time Zone Name: %s \r\n”, tzInfo.DaylightName);
wprintf(L“Daylight Bias: %i Minutes (or %i Hours) \r\n”, tzInfo.DaylightBias, tzInfo.DaylightBias / 60);
wprintf(L“Standard: Occurs %s %s of %s at %i:%2i\r\n”,
wprintf(L“Daylight: Occurs %s %s of %s at %i:%2i\r\n”,
wprintf(L“Bias: %i Minutes (or %i Hours) \r\n”, tzInfo.Bias, tzInfo.Bias / 60);