Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display updated time as system time on a label using c#?

I want to display current time on a label using C# but time will continuously change as system time changes. How can I do this?

like image 818
Akshay Avatar asked Feb 17 '11 06:02

Akshay


People also ask

How to display current time in label in c#?

You can get the current time using something like DateTime. Now . Save this answer.

How will you print the date using C#?

C# today's date Now; Console. WriteLine(now. ToString("F")); The example prints today's date.


2 Answers

Add a new Timer control to your form, called Timer1, set interval to 1000 (ms), then double click on the Timer control to edit the code-behind for Timer1_Tick and add this code:

this.label1.Text = DateTime.Now.ToString();
like image 144
servermanfail Avatar answered Nov 15 '22 21:11

servermanfail


You can Add a timer control and specify it for 1000 millisecond interval

  private void timer1_Tick(object sender, EventArgs e)
    {
        lblTime.Text = DateTime.Now.ToString("dd-MMM-yyyy hh:mm:ss tt");
    }
like image 29
V4Vendetta Avatar answered Nov 15 '22 19:11

V4Vendetta