Пример #1
0
        /// <summary>
        /// Tries to update the current time zone within Windows System Settings and displays a notification of the result
        /// </summary>
        /// <param name="timeZoneName">String display name of the new timezone to be set</param>
        /// <returns>True if the operation is successful, otherwise false</returns>
        public bool UpdateTimeZone(string timeZoneName)
        {
            _resultsText = SystemSettingsUpdateErrorText;

            try
            {
                if (TimeZoneSettings.CanChangeTimeZone)
                {
                    TimeZoneSettings.ChangeTimeZoneByDisplayName(timeZoneName);

                    if (timeZoneName == TimeZoneSettings.CurrentTimeZoneDisplayName)
                    {
                        _updateSuccess = true;
                        _resultsText   = string.Format(TimeZoneUpdateSuccessText, timeZoneName);
                    }
                }
            }
            catch (Exception ex)
            {
                LogService.Write(ex.ToString(), LoggingLevel.Error);
            }
            finally
            {
                PageService?.ShowNotification(_resultsText, 2000);
            }

            return(_updateSuccess);
        }
Пример #2
0
        public static void ChangeTimeZone(string timeZone)
        {
            if (!TimeZoneSettings.CanChangeTimeZone)
            {
                return;
            }

            if (!TimeZoneSettings.SupportedTimeZoneDisplayNames.Contains(timeZone))
            {
                throw new ArgumentException("timeZone");
            }

            TimeZoneSettings.ChangeTimeZoneByDisplayName(timeZone);

            // "Workaround" to flush TimeZoneInfo cache. Yes, this really works.
            TimeZoneInfo.ConvertTime(DateTime.MinValue, TimeZoneInfo.Local);
        }