I'm trying to convert a 24 hour time to 12 hour with AM/PM. I've tried to use the documentation for date/time formats.
Here's my code:
The first problem is that TimeParse won't parse a time with the format "HH:mm" for the time of "21:00." I have to add :00 on the end of the string to make that work. The next problem happens when I try to get the time formatted to "h:mm a", which according to documentation should yield "9:00 PM". What I actually get is "21:00:00".
I can of course write code to do all this manually, but I am puzzled about why this won't work.
Here's my code:
B4X:
Dim TimeString as String = "21:00"
DateTime.DateFormat="HH:mm"
Dim TimeValue=DateTime.TimeParse(TimeString&":00") as Long
DateTime.DateFormat= "h:mm a"
Log(DateTime.Time(TimeValue))
The first problem is that TimeParse won't parse a time with the format "HH:mm" for the time of "21:00." I have to add :00 on the end of the string to make that work. The next problem happens when I try to get the time formatted to "h:mm a", which according to documentation should yield "9:00 PM". What I actually get is "21:00:00".
I can of course write code to do all this manually, but I am puzzled about why this won't work.