Link to home
Start Free TrialLog in
Avatar of VBdotnet2005
VBdotnet2005Flag for United States of America

asked on

Military time

I need a textbox that except military time only. Should I use datetime.now.tostring(format...? Thank you in advance.
For example right now is 9:10 pm - military time is  2110
Avatar of Sinoj Sebastian
Sinoj Sebastian
Flag of India image

Try this

<asp:TextBox id="TBTime" style="Z-INDEX: 101; LEFT: 128px; POSITION: absolute; TOP: 152px" runat="server"></asp:TextBox>
                  <asp:RegularExpressionValidator id="RegularExpressionValidator1" style="Z-INDEX: 102; LEFT: 296px; POSITION: absolute; TOP: 152px"
                        runat="server" ErrorMessage="Invalid Time" ValidationExpression="(([01][0-9])|(2[0-3]))[0-5][0-9]" ControlToValidate="TBTime"></asp:RegularExpressionValidator>
                  <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.
Avatar of VBdotnet2005

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).ToCharArray()
        TBTime.Text() = Date.Parse(a(0) + a(1) + ":" + a(2) + a(3)).ToShortTimeString
    End Sub
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
Avatar of Sinoj Sebastian
Sinoj Sebastian
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial