a blog for those who code

Friday 1 July 2016

How to get Timezone ID's in C#

In this post we will be discussing about getting the Timezone ID's in C#. There might be scenario where you need to give the exact Timezone Id when using TimeZoneInfo.FindTimeZoneById() or TimeZoneInfo.FindSystemTimeZoneById(), so for you need to know the exact id's of all the timezone.


Code to Get Timezone ID's is :



class Program
{
  static void Main(string[] args)
  {
    foreach(TimeZoneInfo tz in TimeZoneInfo.GetSystemTimeZones())
    {
       Console.WriteLine(tz.Id);   
     }
  }
}

Along with that if you want to know the UTC Offset Value, or Standard Name or Display Name you can use tz.BaseUtcOffset, tz.StandardName or tz.DisplayName). This will give the result as :


For more information about Time Zone Index Values you can refer to the MSDN which has the concise Time Zone values as shown below.


Please Like and Share the CodingDefined.com Blog, if you find it interesting and helpful.


No comments:

Post a Comment