C#显示动态显示时间,可以在窗体上添加一个Label,然后使用以下代码:
private void Form_Load(object sender, EventArgs e)
{
Timer time = new Timer();
time.Enabled = true;
time.Interval = 1000;
time.Tick += timerCD_Tick;
}
private void timerCD_Tick(object sender, EventArgs e)
{
this.labInfor.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
//加载窗体时显示当前时间在lablel1上,双击窗体边框把代码复制上来
private void TestForm_Load(object sender, EventArgs e)
{
this.timer1.Enabled = true;
this.label1.Text = DateTime.Now.ToString();
}
//让加载的时间动起来,双击time控件 把代码复制上来
private void timer1_Tick(object sender, EventArgs e)
{
this.label1.Text = DateTime.Now.ToString();
}
写在time控件的Tick事件里面 自己看看吧time控件只有那个事件
把this.textBox1.Text = Convert.ToString(DateTime.Now.ToLocalTime());
写在那里面
楼上讲的是 ASP.NET里面的局部刷新
不知道你写的是windowsForm 还是 asp.net
双击timer控件,添加事件代码
private void timer1_Tick(object sender, EventArgs e)
{
this.textBox1.Text = Convert.ToString(DateTime.Now.ToLocalTime());
}
private void timer1_Tick(object sender, EventArgs e)
{
this.textBox1.Text = DateTime.Now.ToString();//这就是本地时间
}