Bug? DateTime.Time ignores TimeFormat when in 24 hr mode

Jack Cole

Well-Known Member
Licensed User
Longtime User
It seems there is a bug that happens on iOS when the phone is set to 24-hour mode. It seems to ignore the TimeFormat when you try to get the time string from the ticks value.

Dim TimeVal=DateTime.DateTimeParse(DateTime.Date(DateTime.Now),"07:00") As Long
DateTime.TimeFormat="hh:mm a"
Log("Converted time = "&DateTime.Time(TimeVal))

Here is the log output:
Converted time = 07:00

Turn off 24-hour mode on the phone and you get:
Converted time = 07:00 AM

I think the result should be the same regardless of the time mode the phone is in. Am I missing something or is this a bug?


Licensed User
Longtime User
As a guess I would think that 19:00 would return 07:00 PM, so you can tell the difference when not in 24 Hour mode. But I can't test it.


B4X founder
Staff member
Licensed User
Longtime User
It is fixed for the next update. The locale of the internal date and time formatters will be explicitly set to en_US_POSIX.

As a workaround call this sub when the program starts and pass "en_US_POSIX":
Sub SetDateTimeLocale (locale As String)
   Dim loc As NativeObject
   loc = loc.Initialize("NSLocale").RunMethod("localeWithLocaleIdentifier:", Array(locale))
   Dim no As NativeObject = DateTime
   no.GetField("dateFormat").SetField("locale", loc)
   no.GetField("timeFormat").SetField("locale", loc)
End Sub