Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Converting to military time

0 views
Skip to first unread message

Elissa Setarehshenas

unread,
Mar 11, 2002, 3:43:31 PM3/11/02
to

Is there a way to convert the Time into military Time? If the user
inputs 2:15 pm is there a way to convert it 14:15?

Thanks
Elissa

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

GO

unread,
Mar 11, 2002, 5:11:32 PM3/11/02
to
cant you just add 12 to the hour if 1pm or later.

1pm + 12 = 13
2pm + 12 = 14
3:25pm + 12 = 15:25
...
11:59pm + 12 = 23:59

midnight starts at 00:00
12:00AM = 00:00

"Elissa Setarehshenas" <elissa...@yahoo.com> wrote in message
news:#Iiso1TyBHA.2228@tkmsftngp07...

Ken Cox [Microsoft MVP]

unread,
Mar 11, 2002, 5:47:37 PM3/11/02
to
There are some very powerful functions in .NET for this type of conversion.
Here's one that I came up with that seems to handle quite a few formats.

Dim miltime As New DateTime()
Try
miltime = Convert.ToDateTime(TextBox1.Text)
Label1.Text = miltime.ToString("HH:mm:ss")
Catch exc As Exception
Label1.Text = "Problem: " & exc.Message
End Try

Does this help?

Ken
MVP [ASP.NET]

Public Class timemilitary
Inherits System.Web.UI.Page
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim miltime As New DateTime()
Try
miltime = Convert.ToDateTime(TextBox1.Text)
Label1.Text = miltime.ToString("HH:mm:ss")
Catch exc As Exception
Label1.Text = "Problem: " & exc.Message
End Try
End Sub
End Class

"Elissa Setarehshenas" <elissa...@yahoo.com> wrote in message
news:#Iiso1TyBHA.2228@tkmsftngp07...
>
>

0 new messages