Powered by Blogger.

Tuesday, March 11, 2014

Get all time zones in C#.Net

In this post we will discuss how to get all time zones in Asp.Net using C#.Net.

Also you can check out some posts on:

- Convert ArrayList to String using C#.Net

- Object Oriented Programming (OOP) concepts in .Net

- List all Stored Procedure Created and Modified in Last N Days in SQL Server 2008

Here we will bind all the system time zones to a dropdownlist.

Below is the full code:

Select TimeZone: <asp:DropDownList ID="ddlTimeZone" runat="server">

void BindAllTimeZones()
        foreach (TimeZoneInfo timeZone in TimeZoneInfo.GetSystemTimeZones())


The above code will bind all the timezones like below:

If you want to get the system timezone, then you can do like below:

TimeZoneInfo tlocal = TimeZoneInfo.Local;

ddlTimeZones.SelectedItem.Text = tlocal.ToString();