CurrentLocalTimeForTimeZone
public static DateTime CurrentLocalTimeForTimeZone(this TimeZoneInfo tzi) { return System.TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTime.Now, tzi.Id); }Example:
static int Main() { ReadOnlyCollection<TimeZoneInfo> arrTzi = TimeZoneInfo.GetSystemTimeZones(); foreach(TimeZoneInfo tzinfo in arrTzi) { DateTime dt = tzinfo.CurrentLocalTimeForTimeZone(); Console.Write(tzinfo.Id); Console.Write(" "); Console.Write(tzinfo.DisplayName); Console.Write(" : "); Console.WriteLine(dt.ToString("F")); } return 0; }
Description
Returns the current local time for the specified time zone.
Details
- Author: Greg Lyon
- Submitted on: 14-5-2009 01:07:21
- Language: C#
- Type: System.TimeZoneInfo
- Views: 1846
Double click on the code to select all.