public Clock() { InitializeComponent(); _canvas.DataContext = this; TimeInfo = new Data.TimeInfo(TimeZoneInfo.Local); _timer = new DispatcherTimer(); _timer.Interval = new TimeSpan(0, 0, 0, 0, 100); _timer.Tick += new EventHandler(_timer_Tick); _timer.Start(); }
private void _timer_Tick(object sender, EventArgs e) { Data.TimeInfo ti = TimeInfo; if (ti == null) { HourAngle = MinuteAngle = SecondAngle = 0; } else { double hour = ti.GetAdjusted(DateTime.UtcNow).Hour; double minute = ti.GetAdjusted(DateTime.UtcNow).Minute; double second = ti.GetAdjusted(DateTime.UtcNow).Second; double hourAngle = 30 * hour + minute / 2 + second / 120; double minuteAngle = 6 * minute + second / 10; double secondAngle = 6 * second; HourAngle = hourAngle; MinuteAngle = minuteAngle; SecondAngle = secondAngle; } }
public static TimeInfo Read(string s) { try { XDocument xDoc = XDocument.Parse(s); TimeZoneInfo tzi = TimeZoneInfo.FromSerializedString(xDoc.Element("TimeInfo").Attribute("TimeZoneInfo").Value); TimeInfo ti = new TimeInfo(tzi); string displayName = xDoc.Element("TimeInfo").Attribute("DisplayName").Value.Trim(); if (displayName != string.Empty) { ti.DisplayName = displayName; } return(ti); } catch { return(null); } }