Retrieving all time zones and their respective current times
The code will help you to retrieve all the time zones present in the registry and their respective current times.
Class used: TimeZoneInfo: It represents any time zone in the world. The TimeZoneInfo class offers significant enhancements over the TimeZone class, which provides only limited functionality.
Instance of TimeZoneInfo class is immutable, i.e., when we instantiate it the value can't be modified.
more about the class can be read here:
http://msdn.microsoft.com/en-us/library/system.timezoneinfo(v=vs.110).aspx
//retrieve all the timezones from regirtsy
var timeZones = TimeZoneInfo.GetSystemTimeZones();
var myTimezne = timeZones.Select(timeZone => timeZone.Id).ToList();
//iterate through all the timezones and print their ids and current date and time as per that id
foreach (var zoneId in myTimezne)
{
//Get current date and time information from the specified TimeZone
var localtime = DateTime.Now;
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(zoneId);
var dataTimeByZoneId = TimeZoneInfo.ConvertTime(localtime, TimeZoneInfo.Local, timeZoneInfo);
Console.WriteLine("Zone : " + zoneId + " DateTime : " + dataTimeByZoneId);
}
Console.ReadLine();