So let's say I have 1400, I want to convert it into 2:00PM
I tried the following:
Dim convertedTime As String = DateTime.ParseExact(theTime,"HHmm", Nothing)
And it would give me this:
6/12/2012 02:00:00 PM
I do not want the date part, neither do I need the seconds. All I need is 2:00PM
How could I achieve this? Thanks!
Converting from 24 hour to 12 hour clock Starting from the first hour of the day (0:00 / midnight to 0:59), add 12 hours and AM to the time: 0:30 = 12:30 AM. 0:55 = 12:55 AM.
The ParseExact
method returns a DateTime
value, not a string. If you assign it to a string variable you will be converting it automatically, which uses the standard formatting.
If you want it in a specific format, then format the DateTime
value as a string:
Dim d As DateTime = DateTime.ParseExact(theTime,"HHmm", Nothing);
Dim convertedTime As String = d.ToString("hh:mm tt")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With