Results 1 to 7 of 7

Thread: displaying time in vb.net

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    37

    displaying time in vb.net

    hi

    in vb we can write this code in this way for displaying time

    dim cmin as integer,dim csec as integer,dim chrs as integer

    label1.text=format(chrs & ":" & cmin & ":" & csec,"hh:mm:ss")

    here csec , cmin , chrs are incremented using the timer.

    now can i do this in vb.net

    when i write the above code in vb.net , it is just displaying me the hh:mm:ss only
    plz help its very urgent

    thanking you all .

  2. #2
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: displaying time in vb.net

    I don't quite understand which you want here. If you want the time in hours, minutes, and seconds you can just use:
    Code:
    Private Sub Timer1_Tick
    Label1.Text = TimeOfDay.ToString
    End Sub
    That will display your time and keep it up with the time of the day as long as your interval is set to 1000 and is enabled.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: displaying time in vb.net

    Don't store the hours, minutes and seconds in separate variables. Store the whole lot in a DateTime variable.
    vb Code:
    1. Label1.Text = myDate.ToString("HH:mm:ss")
    If you do have them in separate variables then there's no time format string used because your not formatting a time. You're just formatting a bunch of numbers:
    vb Code:
    1. Label1.Text = String.Format("{0:D2}:{1:D2}:{2:D2}", chrs, cmin, csec)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: displaying time in vb.net

    Hey Jmc

    I tried using myDate but it isn't a key word for me, any ideas on why?
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: displaying time in vb.net

    Quote Originally Posted by Abrium
    Hey Jmc

    I tried using myDate but it isn't a key word for me, any ideas on why?
    'myDate' is my date. You should use your date.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2007
    Posts
    37

    Re: displaying time in vb.net

    Quote Originally Posted by jmcilhinney
    Don't store the hours, minutes and seconds in separate variables. Store the whole lot in a DateTime variable.
    vb Code:
    1. Label1.Text = myDate.ToString("HH:mm:ss")
    If you do have them in separate variables then there's no time format string used because your not formatting a time. You're just formatting a bunch of numbers:
    vb Code:
    1. Label1.Text = String.Format("{0:D2}:{1:D2}:{2:D2}", chrs, cmin, csec)

    Thnx a lot for ur reply. it has really worked me. i was just wondering how to do it since this morning.

  7. #7
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: displaying time in vb.net

    humor is always the best medicine...
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

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