Converting to military time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

Is it a function to convert time to and from military time?
Thanks
 
Hi

Is it a function to convert time to and from military time?
Thanks

Theres a whole bunch of things to do with time using "now"
Eg.

msgbox(now.ToUniversalTime)

Will give you the current UTC regardless of your timezone.
if you want it in 24-hour clock:

format(now.ToUniversalTime,"HH:mm:ss")

(captial HH for 24 hours)
 
Al
DateTime always stores "time" in 24 hour (military time) format. It just
varies how you display it.

As Scott suggests you can use a custom format to change how time is
displayed & parsed.

Const militaryTimeFormat As String = "HH:mm"

' convert to a string in military time
Dim input As String = DateTime.Now.ToString(militaryTimeFormat)

' convert from a string in military time
Dim time As DateTime = DateTime.ParseExact(input,
militaryTimeFormat, Nothing)


For details on custom datetime formats see:

http://msdn.microsoft.com/library/d...s/cpguide/html/cpcondatetimeformatstrings.asp

For information on formatting in .NET in general see:
http://msdn.microsoft.com/library/d...y/en-us/cpguide/html/cpconformattingtypes.asp

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top