How do I display time and date (in real-time) in a label in the following format:
May 6, 2004
12:06:32 PM
I know this is probably very simple but I can't seem to make it work.
Thanks in adavance
Brad Nichols
Printable View
How do I display time and date (in real-time) in a label in the following format:
May 6, 2004
12:06:32 PM
I know this is probably very simple but I can't seem to make it work.
Thanks in adavance
Brad Nichols
You can use the FormateDateTime function.
VB Code:
MessageBox.Show(FormatDateTime(Now.ToLongTimeString)) MessageBox.Show(FormatDateTime(Today, DateFormat.LongDate))
But how can i get it to display in a Label on the MDIParent?
I'm sorry i am new to all this, trying to learn though.
Thanks again
Brad Nichols
Ok on the MDIParent form in the upper right hand corner I want to display the date and time in 2 different Labels. (i.e. Label1 = Thursday, May 6, 2004 Label2 = 5:26:34 P.M.). Also is it possible to display it in real-time like have the seconds count on screen? Please help
Thanks in advance
Brad Nichols
I don't get the MDI stuff, but you usually just put something like
VB Code:
Label1.Text = Now.ToLongTimeString
inside the tick event of a timer and set the interval to 1000. If you do this, it will not be exactly identical to the system clock, but it's not that noticable.
Ok here's what i've got. Now how do I get it to display?
VB Code:
Private Sub InitializeTimer() ' Run this procedure in an appropriate event. ' Set to 1 second. Clock.Interval = 1000 ' Enable timer. Clock.Enabled = True End Sub Private Sub Clock_Tick(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles Clock.Tick ' Set the caption to the current time. lblTime.Text = Now.ToLongTimeString lblDate.Text = Now.ToLongDateString End Sub
Where do you call the initialize Timer fucntion?
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Interval = 1000 Timer1.Enabled = True End Sub Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Label1.Text = Now End Sub
This is all I have in a form and it works no problem.
It works Thanks