|
-
Jul 26th, 2007, 10:00 PM
#1
Thread Starter
Fanatic Member
[2.0] date/time
how to set the time, using this code doesnt work;
label1.caption = datetime.now
label2.caption = time
-
Jul 26th, 2007, 11:49 PM
#2
Re: [2.0] date/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:
C# Code:
DateTime currentTime = DateTime.Now;
label1.Text = currentTime.ToShortDateString();
label2.Text = currentTime.ToShortTimeString();
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.
-
Jul 31st, 2007, 04:55 AM
#3
Registered User
Re: [2.0] date/time
Code:
DateTime d=new DateTime();
MessageBox.Show(d.Date.ToShortDateString());
Try this code this will work
-
Jul 31st, 2007, 07:34 AM
#4
Re: [2.0] date/time
 Originally Posted by RaviIntegra
Code:
DateTime d=new DateTime();
MessageBox.Show(d.Date.ToShortDateString());
Try this code this will work
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.
-
Aug 1st, 2007, 05:34 AM
#5
Fanatic Member
Re: [2.0] date/time
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|