I have a program that runs the following code on C#:
TimeZoneInfo localZone = TimeZoneInfo.Local;
string timeZone = TimeZoneInfo.FindSystemTimeZoneById(localZone.Id).ToString();
MessageBox.Show("Local Time Zone ID: " + timeZone);
When I run this, I got the following exception:
System.TimeZoneNotFoundException: The time zone ID 'Malay Peninsula Standard Time' was not found on the local computer.
I made a slight modification on the code and used this line:
TimeZoneInfo localZone = TimeZoneInfo.Local;
MessageBox.Show("Local Time Zone ID: " + localZone.StandardName);
And this time I got no exception, and I got the popup message with the time zone "Malay Peninsula Standard Time"
Why the first fragment of code is not working?
After some time (days), I finally found out what was happening.
Debugging the code, I see that TimeZoneInfo.Local.Id was retrieving the following value:
Malay Peninsula Standard Time
I made some investigation, and found out that all the time zones for the server are stored on this registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\
If you browse through them, you will see that no key is called "Malay Peninsula Standard Time", the value that is for that time zone is "Singapore Standard Time". The whole information for that time zone is the following:
ID: Singapore Standard Time
Display Name: (GMT+08:00) Kuala Lumpur, Singapore
Standard Name: Malay Peninsula Standard Time
Daylight Name: Malay Peninsula Daylight Time ***Does Not Have Daylight Saving Time***
Offset from UTC: 8 hours, 0 minutes
Number of adjustment rules: 0
So, as you see, the ID that I was looking for did not exist, and that's why I got that exception. I renamed the registry key to "Malay Peninsula Standard Time" and the problem was gone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With