Skip to content

Entering the time and date on a form

Joshua Bell

Asked Nov 3, 2005, 10:50 AM EST2 answers
Share
LinkedInX
How do I put in the time and date on a form in VB.NET? I did what my book has told me but all it shows up as is 01/01/2000 on the date and the time reads 12:01:01 and doesn't change. So how do I make it show the correct time and date? There is another part in my book that explains how to put it in the status bar but I don't want to put them in the status bar. Please help me!

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Problem easily solved.  I'm pretty sure this is what your looking for.
    1. Add A timer to your form.
    2. Click on timer and then click on property's. 
    3. Set enabled to True;  Set Interval to 1000   (this causes the timer to tick;  1000 will tick every second.
    4. Double click the timer and insert the following code.

    label1.Text = CStr(Date.Today.Now)

    5. Remember that label1 here is representing whatever you are using and should be replaced with your object.  Example:  If you want the forms' text to display the time, then use me.text = ....
    6. Run the program and watch it keep time.

    You can play with the Date class and get different displays of time and date.  Hope this helps :)

    0