title: Converting utc offset value to time zone info in .NET Core 3.x
body: <p>Before I reinvent the wheel, I wanted to see if there was a built in way in .NET Core 3.1 to get a list of possible time zone names from an UTC offset value?</p>
  
  <p>The <code>utcOffset</code> value is an <code>int</code> value that can be positive or negative. This is the <code>utcOffset</code> captured by a JavaScript client and sent to my ASP.NET Core 3.1 backend API. I just need to figure out a way to convert this to time zone name e.g. <code>Mountain Standard Time</code>, etc.</p>
  
  <p>Here's my solution so far as I couldn't find a direct way to handle this but .NET Core 3.1 definitely gives us enough to work with.</p>
  
  <pre><code>public static string GetTimeZoneNameFromUtcOffset(int utcOffset)
  {
      var timeZoneName = string.Empty;
  
      var possibleTimeZones = new List&lt;string&gt;();
  
      foreach(var tz in TimeZoneInfo.GetSystemTimeZones())
      {
          if(tz.GetUtcOffset(DateTime.UtcNow).TotalMinutes == utcOffset)
             possibleTimeZones.Add(tz.DisplayName);
      }
  
      if(possibleTimeZones.Count &gt; 0)
          timeZoneName = possibleTimeZones[0]; // Not the best way but what I have so far
  
      return timeZoneName;
  }
  </code></pre>