Results 1 to 8 of 8

Thread: Displaying time and date * * RESOLVED * *

  1. #1

    Thread Starter
    Member
    Join Date
    May 2004
    Posts
    36

    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.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    You can use the FormateDateTime function.

    VB Code:
    1. MessageBox.Show(FormatDateTime(Now.ToLongTimeString))
    2.  
    3. MessageBox.Show(FormatDateTime(Today, DateFormat.LongDate))

  3. #3

    Thread Starter
    Member
    Join Date
    May 2004
    Posts
    36
    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

  4. #4

    Thread Starter
    Member
    Join Date
    May 2004
    Posts
    36
    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

  5. #5
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718
    I don't get the MDI stuff, but you usually just put something like

    VB Code:
    1. 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)

  6. #6

    Thread Starter
    Member
    Join Date
    May 2004
    Posts
    36
    Ok here's what i've got. Now how do I get it to display?

    VB Code:
    1. Private Sub InitializeTimer()
    2.         ' Run this procedure in an appropriate event.
    3.         ' Set to 1 second.
    4.         Clock.Interval = 1000
    5.         ' Enable timer.
    6.         Clock.Enabled = True
    7.     End Sub
    8.  
    9.     Private Sub Clock_Tick(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles Clock.Tick
    10.         ' Set the caption to the current time.
    11.         lblTime.Text = Now.ToLongTimeString
    12.         lblDate.Text = Now.ToLongDateString
    13.     End Sub

  7. #7
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Where do you call the initialize Timer fucntion?

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Timer1.Interval = 1000
    3.         Timer1.Enabled = True
    4.  
    5.  
    6.     End Sub
    7.  
    8.     Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    9.         Label1.Text = Now
    10.     End Sub

    This is all I have in a form and it works no problem.

  8. #8

    Thread Starter
    Member
    Join Date
    May 2004
    Posts
    36
    It works Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width