How to Format time in vb.net

I read the date and time value from the array as:
"15-APR-2005 01:00:00 PM"

I want to grab only time and if it is PM then I want to format for 1:00:00 PM as: 1300,1400,1500 and so on...,
else if it is AM then for 1:00:00 AM I want to format as 100,200,300... and so on.


Thanks
vm
vmandemAsked:
Who is Participating?
 
S-TwilleyConnect With a Mentor Commented:
alternatively:

Dim CurrentTime as DateTime
Dim sCurrentTime as String
CurrentTime = DateTime.Now

sCurrentTime = CurrentTime.ToString("H:mm")  ' if you want the colon

or

sCurrentTime = CurrentTime.ToString("Hmm")  ' if you don't want the colon
0
 
jong3Commented:
Assuming you are using a DateTime object, you can do something like the following:

Dim CurrentTime as DateTime
Dim CurrentMilitaryTime as String
CurrentTime = DateTime.Now

CurrentMilitaryTime = CurrentTime .Hour.ToString() & CurrentTime.Minute.ToString()



the Hour member will return a hour between 0 - 23
So, this
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.