By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,386 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,386 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Feb 1 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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

Feb 1 '06 #2

P: n/a
"Rich" <Ri**@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

Feb 1 '06 #3

P: n/a
Rich,

TimeOfDay.ToLongTimeString

Kerry Moorman
"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

Feb 1 '06 #4

P: n/a
Thanks all for your replies.

"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

Feb 1 '06 #5

P: n/a
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" <Ri**@discussions.microsoft.com> wrote in message
news:DC**********************************@microsof t.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

Feb 1 '06 #6

P: n/a
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

"james" <jj***************@earthlink.net> wrote in message
news:%2***************@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" <Ri**@discussions.microsoft.com> wrote in message
news:DC**********************************@microsof t.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


Feb 1 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.