1 DispatcherTimer = new DispatcherTimer(); 2 Timer.Tick += Timer_Tick; 3 Timer.Interval = TimeSpan.FromSeconds(1); 4 Timer.Start(); 5 6 7 private void Timer_Tick(object sender, EventArgs e) 8 { 9 //todo 10 //获取温度的数值 11 12 //获取年月日 13 string dt_ymd = DateTime.Now.ToLongDateString(); 14 this.LbYearAndMonth.Content = dt_ymd; 15 //获取几时几分 16 string dt_hm = DateTime.Now.ToShortTimeString(); 17 this.LbHourAndMin.Content = dt_hm; 18 19 //获取今天是星期几 20 string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; 21 string week = Day[Convert.ToInt32(DateTime.Now.DayOfWeek.ToString("d"))].ToString(); 22 this.LbWeekday.Content = week; 23 }