Android Question How to show time Hr:Min AM/PM

Nitin Joshi

Active Member
Licensed User
I am using below code to message set on time. Messages shows time as 14:00:00 however i want to show time as 2:00 PM. Please suggest.
Time Value:
MsgboxAsync ("On Time: " &  DateTime.Time(DateTime.TimeParse(14 & ":" & 0 & ":" & 0)),"")
 

Mahares

Expert
Licensed User
Longtime User
i want to show time as 2:00 PM. Please suggest.
Something like this:
B4X:
Dim s As String =14 & ":" & 0 & ":" & 0    
    Dim l As Long =DateTime.TimeParse(s)
    DateTime.Timeformat ="hh:mm:ss a"  
    Log(DateTime.Time(l))  '02:00:00 PM
remove the seconds from the format if you do not want them
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
DateTime.Timeformat is a string so you can save it before the change and restore it afterwards.

eg.
B4X:
private originaltimeformat as string = datetime.timeformat
DateTime.Timeformat ="hh:mm:ss a" 
Log(DateTime.Time(l))  '02:00:00 PM
datetime.timeformat = originaltimeformat
 
Upvote 0

Nitin Joshi

Active Member
Licensed User
One more thing, if i want 24 hour time format then below syntax is correct?
B4X:
 DateTime.Timeformat="hh:mm"

Aslo, how to parse time when I set time format as "hh:mm a"?
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
There is a link in the description to the format methods.
1608564614536.png

The one for time format links to this page https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
 
Upvote 0
Top