|
-
May 6th, 2004, 12:12 PM
#1
Thread Starter
Member
Displaying time and date * * RESOLVED * *
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
Last edited by jnichols; May 7th, 2004 at 02:28 PM.
-
May 6th, 2004, 12:22 PM
#2
You can use the FormateDateTime function.
VB Code:
MessageBox.Show(FormatDateTime(Now.ToLongTimeString))
MessageBox.Show(FormatDateTime(Today, DateFormat.LongDate))
-
May 6th, 2004, 03:03 PM
#3
Thread Starter
Member
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
-
May 6th, 2004, 09:43 PM
#4
Thread Starter
Member
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
-
May 7th, 2004, 01:31 AM
#5
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.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
May 7th, 2004, 10:54 AM
#6
Thread Starter
Member
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
-
May 7th, 2004, 01:02 PM
#7
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.
-
May 7th, 2004, 02:27 PM
#8
Thread Starter
Member
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
|