find current moscow time using c#

.net, c#, timezone

Solution

You need to patch your system. On my system (Windows 7 with all updates installed) it gives the correct time:

DateTime.UtcNow.Dump();
TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Russian Standard Time")).Dump();

output:

17/12/2013 09:11:08
17/12/2013 13:11:08

Microsoft has released an update a while ago to accomodate Russian DST law changes, you obviously don't have it.

*Dump() is an extension method provided by LINQPad. Equivalent of Console.WriteLine(<...>.ToString())

Problem

I'm trying to get local Moscow time in my .NET application. Here is how far I went: ``` private static Dictionary<TimeZoneEnum, string> timeZoneDict = new Dictionary<TimeZoneEnum, string>() { {TimeZoneEnum.RussiaStandardTime, "Russian Standard Time"} }; public static DateTime GetDateTimeNowForTimeZone(TimeZoneEnum timezone) { DateTime result = TimeZoneInfo.ConvertTime(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById(timeZoneDict[timezone])); return result; } ``` Method GetDateTimeNowForTimeZone gives me GMT+3 time but now in russia there is GMT+4 time. Is there anyu way to get robust solution for this issue in .net framework ?

Original source