
代码如下:
private void Form1_Load(object sender, EventArgs e)
{
_nowtimes();
}
private System.Threading.Timer _times;
private string oldsday = "";
private void _nowtimes()
{
_times = new System.Threading.Timer(new System.Threading.TimerCallback(Ntimes), null, 0, 1000);
_times.Change(1, 1000);
}
private void Ntimes(object state)
{
string nows = System.DateTime.Now.ToString("T");
string dates = System.DateTime.Now.ToString("D");
this.BeginInvoke(new Action(() =>
{
if (oldsday != dates)
{
Label_day.Text = dates;
oldsday = dates;
}
Label_NowTime.Text = nows.ToString();
}), null);
}
|