WPF 显示时间

来源:互联网 发布:网络认证系统 编辑:程序博客网 时间:2024/06/05 06:31
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using System.ComponentModel;using System.Windows.Threading;//引用namespace WpfApplication2{    /// <summary>    /// MainWindow.xaml 的交互逻辑    /// </summary>    public partial class MainWindow : Window    {        public MainWindow()        {            InitializeComponent();        }        private void label1_Loaded(object sender, RoutedEventArgs e)        {            DispatcherTimer timer = new DispatcherTimer();            timer.Interval = new TimeSpan(0, 0, 1);   //间隔1            timer.Tick += new EventHandler(timer_Tick);            timer.Start();        }        void timer_Tick(object sender, EventArgs e)        {            label1.Content = DateTime.Now.ToString("yyyy年MM月dd日 HH时hh分ss秒");//yyyy年MM月dd日 HH:hh:ss 也可以        }    }    }

原创粉丝点击