Home All Groups Group Topic Archive Search About

TimeOfDay adds 1/1/0001 to the Time value?

Author
1 Feb 2006 6:43 PM
Rich
Hello,

I have a label in my app where I display time from a Timer contol like this:

Private Sub Timer1_Tick(...) Handles Timer1.Tick
    lbl_Time.Text = TimeOfDay.ToString
End Sub

The display is 1/1/0001 10:00:01 AM

How can I remove the 1/1/0001   part?

Thanks,
Rich

Author
1 Feb 2006 6:57 PM
Rich
Hmmm, I tried

TimeOfDay.ToShortTime.ToString

which seems to display just the time value  10:07 AM   but no seconds.  Any
suggestions appreciated how I can display a time value in this form:

10:07:23 AM


Show quoteHide quote
"Rich" wrote:

> Hello,
>
> I have a label in my app where I display time from a Timer contol like this:
>
> Private Sub Timer1_Tick(...) Handles Timer1.Tick
>     lbl_Time.Text = TimeOfDay.ToString
> End Sub
>
> The display is 1/1/0001 10:00:01 AM
>
> How can I remove the 1/1/0001   part?
>
> Thanks,
> Rich
Author
1 Feb 2006 7:06 PM
Kerry Moorman
Rich,

TimeOfDay.ToLongTimeString

Kerry Moorman


Show quoteHide quote
"Rich" wrote:

> Hmmm, I tried
>
> TimeOfDay.ToShortTime.ToString
>
> which seems to display just the time value  10:07 AM   but no seconds.  Any
> suggestions appreciated how I can display a time value in this form:
>
> 10:07:23 AM
>
>
> "Rich" wrote:
>
> > Hello,
> >
> > I have a label in my app where I display time from a Timer contol like this:
> >
> > Private Sub Timer1_Tick(...) Handles Timer1.Tick
> >     lbl_Time.Text = TimeOfDay.ToString
> > End Sub
> >
> > The display is 1/1/0001 10:00:01 AM
> >
> > How can I remove the 1/1/0001   part?
> >
> > Thanks,
> > Rich
Author
1 Feb 2006 7:05 PM
Armin Zingler
Show quote Hide quote
"Rich" <R***@discussions.microsoft.com> schrieb
> Hello,
>
> I have a label in my app where I display time from a Timer contol
> like this:
>
> Private Sub Timer1_Tick(...) Handles Timer1.Tick
>    lbl_Time.Text = TimeOfDay.ToString
> End Sub
>
> The display is 1/1/0001 10:00:01 AM
>
> How can I remove the 1/1/0001   part?


ToString is overloaded. Use one of the other versions.

Also consider using Date.TimeOfDay. Returns a TimeSpan object with no
formatting features with the ToString method, but doesn't contain a Date
part.


Armin
Author
1 Feb 2006 7:54 PM
Rich
Thanks all for your replies. 

Show quoteHide quote
"Rich" wrote:

> Hello,
>
> I have a label in my app where I display time from a Timer contol like this:
>
> Private Sub Timer1_Tick(...) Handles Timer1.Tick
>     lbl_Time.Text = TimeOfDay.ToString
> End Sub
>
> The display is 1/1/0001 10:00:01 AM
>
> How can I remove the 1/1/0001   part?
>
> Thanks,
> Rich
Author
1 Feb 2006 10:46 PM
james
How about this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Label1.Text = TimeOfDay.ToString("hh:mm:ss tt")

End Sub

That will give the current time showing only AM/PM instead of the date.
(modify to work with your timer)
james


Show quoteHide quote
"Rich" <R***@discussions.microsoft.com> wrote in message
news:DCE7FC05-CE8F-462E-BE3F-9AA8988DB977@microsoft.com...
> Hello,
>
> I have a label in my app where I display time from a Timer contol like
> this:
>
> Private Sub Timer1_Tick(...) Handles Timer1.Tick
>    lbl_Time.Text = TimeOfDay.ToString
> End Sub
>
> The display is 1/1/0001 10:00:01 AM
>
> How can I remove the 1/1/0001   part?
>
> Thanks,
> Rich
Author
1 Feb 2006 10:55 PM
james
Or even better: (sorry for answering my own response)

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Timer1.Tick

Label1.Text = TimeOfDay.ToString("hh:mm:ss tt")

End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load

Timer1.Interval = 100

Timer1.Enabled = True

End Sub


james





Show quoteHide quote
"james" <jjames700REMOV***@earthlink.net> wrote in message
news:%23uq0MF4JGHA.604@TK2MSFTNGP14.phx.gbl...
> How about this:
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
>
> Label1.Text = TimeOfDay.ToString("hh:mm:ss tt")
>
> End Sub
>
> That will give the current time showing only AM/PM instead of the date.
> (modify to work with your timer)
> james
>
>
> "Rich" <R***@discussions.microsoft.com> wrote in message
> news:DCE7FC05-CE8F-462E-BE3F-9AA8988DB977@microsoft.com...
>> Hello,
>>
>> I have a label in my app where I display time from a Timer contol like
>> this:
>>
>> Private Sub Timer1_Tick(...) Handles Timer1.Tick
>>    lbl_Time.Text = TimeOfDay.ToString
>> End Sub
>>
>> The display is 1/1/0001 10:00:01 AM
>>
>> How can I remove the 1/1/0001   part?
>>
>> Thanks,
>> Rich
>
>