VBdotnet2005
asked on
Military time
I need a textbox that except military time only. Should I use datetime.now.tostring(form at...? Thank you in advance.
For example right now is 9:10 pm - military time is 2110
For example right now is 9:10 pm - military time is 2110
ASKER
If a user input 0651, for example, how can you tell whether it is am or pm, for those whom is not awared of it? Since it excepts it anyway.
I'm sorry, i don't understand what you are taking about.
0000 - 1159 is AM
1200 - 2359 is PM
try this
Private Sub BtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click
Dim Time As Date
Dim a As Char() = Trim(TBTime.Text).ToCharAr ray()
TBTime.Text() = Date.Parse(a(0) + a(1) + ":" + a(2) + a(3)).ToShortTimeString
End Sub
0000 - 1159 is AM
1200 - 2359 is PM
try this
Private Sub BtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSubmit.Click
Dim Time As Date
Dim a As Char() = Trim(TBTime.Text).ToCharAr
TBTime.Text() = Date.Parse(a(0) + a(1) + ":" + a(2) + a(3)).ToShortTimeString
End Sub
ASKER
Can you help me further? What is a user accidently input just a number? It is going to create an error, correct?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<asp:TextBox id="TBTime" style="Z-INDEX: 101; LEFT: 128px; POSITION: absolute; TOP: 152px" runat="server"></asp:TextB
<asp:RegularExpressionVali
runat="server" ErrorMessage="Invalid Time" ValidationExpression="(([0
<asp:Button id="BtnSubmit" style="Z-INDEX: 103; LEFT: 208px; POSITION: absolute; TOP: 192px"
runat="server" Text="Test" Width="72px"></asp:Button>
<asp:Label id="Label1" style="Z-INDEX: 104; LEFT: 56px; POSITION: absolute; TOP: 152px" runat="server">Enter time</asp:Label>
Tell me if you have any problem.