Android Code Snippet [B4X] check if the time format is 12h or 24h format

I needed a way to check if the user lives in 12h or 24h time format to give him the possibility to show an AM/PM switch when selecting a time.

There may be a better way to check this, but if I display the following code on an affected device, I see an "a" at the end which indicates AM/PM.
B4X:
Log(DateTime.DeviceDefaultTimeFormat) 'h:mm a

B4X:
Public Sub is12hTimeFormat As Boolean
    If DateTime.DeviceDefaultTimeFormat.ToLowerCase.Contains("a") Then
        Return True
    Else
        Return False
    End If
End Sub
 

klaus

Expert
Licensed User
Longtime User
In a 24h time format the hour symbol is "H".
In a 12h time format the hour symbol is "h".
So you could check with :
TwelveHourFormat = DateTime.DeviceDefaultTimeFormat.Contains("h")
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…