Exemple #1
0
        /// <summary>
        /// Converts a localTime from a source time zone to a target time zone, adjusting for DST as needed.
        /// The localTime must be a local time in the sourceTimeZoneName time zone.
        /// </summary>
        /// <param name="sourceTimeZoneName">Time zone name which represents localTime.</param>
        /// <param name="localTime">The source local time.</param>
        /// <param name="targetTimeZoneName">The time zone name which to convert the localTime.</param>
        /// <returns>The local time for targetTimeZoneName.</returns>
        public static DateTime ToLocalTime(string sourceTimeZoneName, DateTime localTime, string targetTimeZoneName)
        {
            DateTime utc = TimeZoneInformation.ToUniversalTime(sourceTimeZoneName, localTime);
            DateTime lt  = TimeZoneInformation.ToLocalTime(utc, targetTimeZoneName);

            return(lt);
        }
Exemple #2
0
        public override void Repaint()
        {
            DateTime lUtc = DateTime.UtcNow;

            lock (_Graphic)
            {
                _Graphic.FillRectangle(Brushes.Black, 0, 0, 96, 96);

                for (int i = 0; i < 5; i++)
                {
                    TimezoneItem lItem = _Timezones[i];
                    if (lItem == null)
                    {
                        continue;
                    }

                    string lTime = string.Format("{0} {1}", TimeZoneInformation.ToLocalTime(lUtc, lItem.Timezone.StandardName).ToShortTimeString(), lItem.Label);
                    _Graphic.DrawString(lTime, SystemFonts.DefaultFont, Brushes.White, 0, i * 19);
                }

                _Graphic.Flush();
                UpdateImage(_Bitmap);
            }
        }
Exemple #3
0
        /// <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));
        }