Convert from UTC to USA Mountain Time with DST

I was looking for a way to convert from UTC to mountain time, and I successfully found the following function that everyone says, taking into account the DST. Whenever it is converted from UTC to Mountain, it is always -7 for the offset (when it should be -6 at the moment). Also, it doesn't seem to be that way. Can someone highlight this for me or do it with DST?

DateTime utcTime = new DateTime(createdDate.Ticks, DateTimeKind.Utc); DateTime mountainTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(utcTime, "US Mountain Standard Time"); 

Thanks, Dman

+8
timezone c #
source share
2 answers

There seem to be two zones in .NET (at least on my Windows 8 installation) that are mountainous.

There's a "US Mountain Standard Time" that you use that doesn't watch DST (this is for Arizona) - and a simple "Mountain Standard Time" that watches DST. Therefore, you just need to get rid of the "USA" part, and it will work:

 using System; class Test { static void Main() { DateTime octoberUtc = new DateTime(2012, 10, 1, 0, 0, 0, DateTimeKind.Utc); DateTime decemberUtc = new DateTime(2012, 12, 1, 0, 0, 0, DateTimeKind.Utc); ConvertToMountainTime(octoberUtc); ConvertToMountainTime(decemberUtc); } static void ConvertToMountainTime(DateTime utc) { DateTime mountain = TimeZoneInfo.ConvertTimeBySystemTimeZoneId (utc, "Mountain Standard Time"); Console.WriteLine("{0} (UTC) = {1} Mountain time", utc, mountain); } } 

Output (UK culture):

 01/10/2012 00:00:00 (UTC) = 30/09/2012 18:00:00 Mountain time 01/12/2012 00:00:00 (UTC) = 30/11/2012 17:00:00 Mountain time 
+13
source share

Mountain standard time is still -7. Go to the popular opinion, we do not change our time, but our time is a zone . Our current time zone is actually the time of a summer day. Detecting time zone information ... is unpleasant

+1
source share

All Articles