public override void Initialize(OptimusMiniSettingsList currentSettings) { _Timezones = new TimezoneItem[5]; for (int i = 0; i < 5; i++) { string lTimezone = currentSettings["Timezone" + i.ToString()]; string lLabel = currentSettings["Label" + i.ToString()]; if (lTimezone != "" && TimeZoneInformation.ContainsTimeZone(lTimezone)) { TimezoneItem lItem = new TimezoneItem(TimeZoneInformation.GetTimeZone(lTimezone), lLabel); _Timezones[i] = lItem; } else { _Timezones[i] = null; } } RequestNextUpdate(new TimeSpan(0, 0, 0)); }
public WorldTimeConfig(OptimusMiniSettingsList currentSettings) { InitializeComponent(); _Settings = currentSettings; _Items = new List <TimezoneItem>(); // ----- Fill select box with all timezones foreach (TimeZoneInformation lTimezone in TimeZoneInformation.TimeZones) { selectTimezone.Items.Add(lTimezone.DisplayName); } selectTimezone.SelectedIndex = 0; // ----- Add stored timezones for (int i = 0; i < 5; i++) { string lTimezone = _Settings["Timezone" + i.ToString()]; if (TimeZoneInformation.ContainsTimeZone(lTimezone)) { TimezoneItem lItem = new TimezoneItem(TimeZoneInformation.GetTimeZone(lTimezone), _Settings["Label" + i.ToString()]); _Items.Add(lItem); listTimezones.Items.Add(string.Format("{0}: {1}", lItem.Label, lItem.Timezone.DisplayName)); } } if (_Items.Count > 0) { listTimezones.Items[0].Selected = true; } // ----- Update controls UpdateActions(); }
/// <summary> /// Converts a local time in specified time zone to UTC time. /// </summary> /// <param name="standardTimeZoneName">The standard time zone name.</param> /// <param name="local">The local time to convert.</param> /// <returns>The UTC time.</returns> /// <exception cref="ArgumentException">Thrown if time zone name not found.</exception> /// <exception cref="NotSupportedException">Thrown if the method failed due to missing platform support.</exception> public static DateTime ToUniversalTime(string standardTimeZoneName, DateTime local) { TimeZoneInformation tzi = TimeZoneInformation.GetTimeZone(standardTimeZoneName); return(tzi.ToUniversalTime(local)); }
/// <summary> /// Converts the value of the utc time to local time in supplied time zone. /// </summary> /// <param name="utc">The time to convert.</param> /// <param name="targetTimeZoneName">The standard name of the time zone.</param> /// <returns>The local time.</returns> /// <exception cref="ArgumentException">Thrown if time zone not found.</exception> public static DateTime ToLocalTime(DateTime utc, string targetTimeZoneName) { TimeZoneInformation tzi = TimeZoneInformation.GetTimeZone(targetTimeZoneName); return(tzi.ToLocalTime(utc)); }