One particular thing we need to be careful here is that the information we collected from registry for " StandardName" and " DayLightName" is in ANSI form, but TIME_ZONE_INFORMATION requires these values to be in widechar or Unicode format, so we need to use MultiByteToWideChar() and WideCharToMultiByte() functions to do the necessary conversions wherever necessary. We will fill this TIME_ZONE_INFORMATION structure from the information we retrieved from the registry.
The SystemTimeToTzSpecificLocalTime() API takes TIME_ZONE_INFORMATION, Universal time as input and returns localtime which corresponds to supplied TIME_ZONE_INFORMATION. The following APIs do the necessary conversion from local time in given TimeZone to universal time. TimeZoneComparer( const void *i_TZ1, const void *i_TZ2)
We need to sort time zones based on the offset from GMT or standard bias.Ĭopy Code int CTimeZoneInfoManager::SortTimeZoneList() The comparison function will decide the criteria on which we will sort the code. We need to pass the address of the first element of CArray and a comparison function to qsort(). We need to supply the starting address of the array and a callback comparison function which will get called when sorting the CArray. There are several ways to do this, but I have selected qsort() function. Now we have time zone information in alphabetical form, but we need to have this information sorted on the offset from GMT time (bias). Int CTimeZoneInfoManager::GetFullTimeZoneInfoFromRegistry() will have code which will fill the necessary time zone information structures, which are required for conversion.įinally all the time zone information is collected in the template based class CArray in alphabetical order. We need to retrieve this information, first by enumerating all sub keys under " SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones", then by querying values under each of the sub keys.ĬTimeZoneInfoManager::EnumerateTimeZones() will have related code which would read all sub keys information of " SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones".