• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1769
  • Last Modified:

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
0
vmandem
Asked:
vmandem
1 Solution
 
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
 
S-TwilleyCommented:
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now