|
-
Apr 23rd, 2007, 01:29 AM
#1
Thread Starter
Member
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 .
-
Apr 23rd, 2007, 01:37 AM
#2
Addicted Member
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.
-
Apr 23rd, 2007, 01:37 AM
#3
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:
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:
Label1.Text = String.Format("{0:D2}:{1:D2}:{2:D2}", chrs, cmin, csec)
-
Apr 23rd, 2007, 01:41 AM
#4
Addicted Member
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.
-
Apr 23rd, 2007, 01:43 AM
#5
Re: displaying time in vb.net
 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.
-
Apr 23rd, 2007, 01:45 AM
#6
Thread Starter
Member
Re: displaying time in vb.net
 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:
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:
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.
-
Apr 23rd, 2007, 01:46 AM
#7
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|