C#如何获取动态的系统时间

private void Form1_Load(object sender, EventArgs e) //首先在主窗体添加定时事件
{
            this.timer1.Interval = 1000;//设置定时器触发间隔
            this.timer1.Start();    //启动定时器
            label1.Text = DateTime.Now.ToString();
 }

private void timer1_Tick(object sender, EventArgs e)    //接着在定时器触发事件中添加获取时间和显示时间函数
{
            DateTime time = DateTime.Now;       //获取当前时间
            label1.Font = new Font("宋体",12);  //设置label1显示字体
            this.label1.Text = time.ToString(); //显示当前时间
} 

猜你喜欢

转载自blog.csdn.net/cyx416676411/article/details/77504102