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:) .
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.
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)
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?
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.
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:
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. :)
Re: displaying time in vb.net
humor is always the best medicine...