iOS Question DateTime and locale

Semen Matusovskiy

Well-Known Member
Licensed User
Hi, guys --

Is it possible to set locale on fly for DateTime functions ?
My app already has #PlistExtra: <key>CFBundleLocalizations</key> and this works fine, for example in textfield context menu. But there is no effect for DateTime.DateParse, DateTime.Date etc. Any ideas ?
 

Semen Matusovskiy

Well-Known Member
Licensed User
Thanx for reply. I added a subroutine from your link

B4X:
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

and following statements in Application_Start
B4X:
        SetDateTimeLocale ("de_DE")
        Log (DateTime.Date (DateTime.Now))

Unlike I tried some id, output was the same 05/12/2019.

Note, I use a simulator (which I erase very often). So settings are default - english; US.

Yesterday I tried apple's samples from https://developer.apple.com/documentation/foundation/nsdateformatter
They work fine.

BTW, DateFormat works fine, so there is a workaround anyway.
 
Last edited:
Upvote 0
Top