A very common scenario faced by most of us these days is the conversion of datetime value from UTC to local time zone or from local to UTC or from one local time zone to another local time zone. The matter gets complicated when conversion has to take care of Daylight Saving Time (DST). DST change is applied in different regions at a different date each year. There is no standard pattern of when it will be applied each year. Hence it cannot be determined in advance. Most applications end up with a scheduled manual configuration change task to adjust for clock change.
There are methods available in .Net and other programming languages to automate this process. TimeZoneInfo class represents any time zone in the world. The time zone identifier (Id) property of TimeZoneInfo class is a key string that uniquely identifies a particular time zone. A complete list of all the timezones referenced by the Id property of TimeZoneInfo class can be obtained using below code-
Above code will display a list of time zone Id available in Windows registry. Samples like-
Datetime value can then be converted from UTC to any of above local time zone by using below code-
Similarly, Datetime value can be converted to UTC from any of above local time zone by using below code-
Datetime conversion using above method takes care of daylight savings and hence simplifies overall implementation by removing any manual task.