how to set the time, using this code doesnt work;
label1.caption = datetime.now
label2.caption = time
Printable View
how to set the time, using this code doesnt work;
label1.caption = datetime.now
label2.caption = time
DateTime.Now returns a DateTime object containing the current date and time. DateTime.Today returns a DateTime object containing the current date with the time zeroed to midnight. If you want to display some or all of those values you need to convert them to strings, as you do with all object before displaying them in Labels. Note also that Labels have no Caption property:There are many variations that give you complete control over how the date and/or time is formatted too. See the DateTime.ToString method documentation for more information.C# Code:
DateTime currentTime = DateTime.Now; label1.Text = currentTime.ToShortDateString(); label2.Text = currentTime.ToShortTimeString();
Try this code this will workCode:DateTime d=new DateTime();
MessageBox.Show(d.Date.ToShortDateString());
Gee, why didn't I think of that? Hang on, I did! By all means contribute but suggesting the same thing as someone else days afterwards isn't really a contribution.Quote:
Originally Posted by RaviIntegra
Lol. Very true jmcilhinney.
To OP: You can press F1 on the keyboard in Visual C# Express Edition and use the search feature. You'd be suprised by the amount of info they will have.
EDIT: Changed first sentence after reading jmcilhinney's well explained post. :thumb: