How to display the current time and date in C#

ABCProgrammer picture ABCProgrammer · Dec 7, 2010 · Viewed 121k times · Source

How do you display the current date and time in a label in c#

Answer

Chris Pfohl picture Chris Pfohl · Dec 7, 2010

You'd need to set the label's text property to DateTime.Now:

labelName.Text = DateTime.Now.ToString();

You can format it in a variety of ways by handing ToString() a format string in the form of "MM/DD/YYYY" and the like. (Google Date-format strings).