[RESOLVED] DateTimePicker vb.net 2005
I've got the following piece of code that shows current date and time in a label within timer_tick.
What i want to do is to enable a user to choose time format ie 12 or 24 hr clock.
I know it's something to do with the DateTimePicker but i dont know how to incorporate it within my code.
My time code is the simple code below:
"Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = Now.ToString
End Sub"
Please help!
Re: DateTimePicker vb.net 2005
If all you want to do is select 12 or 24 hour format for a time displayed in a Label then it has nothing to do with a DateTimePicker. It would only involve a DTP if you wanted to display the time in a DTP. You should create a ComboBox and add items "12 hour" and "24 hour" to it. In your Tick event handler you would do this:
vb Code:
Dim timeFormat As String
If timeFormatCombo.SelectedItem = "24 hour" Then
timeFormat = "HH:mm:ss"
Else
timeFormat = "h:mm:ss tt"
End If
timeLabel.Text = Date.Now.ToString(timeFormat)
Probably even better would be if you declared a class-level variable named timeFormat which you set on the SelectedIndexChanged event of your ComboBox:
vb Code:
If Me.timeFormatCombo.SelectedItem = "24 hour" Then
Me.timeFormat = "HH:mm:ss"
Else
Me.timeFormat = "h:mm:ss tt"
End If
Then in the Tick event handler there's no need to calculate the format each time. You just go ahead and use the one that was set last time the user made a selection:
vb Code:
Me.timeLabel.Text = Date.Now.ToString(Me.timeFormat)
Re: DateTimePicker vb.net 2005
Thanks jmcilhinney!
Just a quick question. What do i "Dim timeFormatCombo as"? , and i've put Dim timeLabel As label, is that right?
Thank you!
Re: DateTimePicker vb.net 2005
Hooray!!! jmcilhinney Thank you very much.
It's all working now.
Once again thank you:D