iOS Question Day of week english/locale

marcick

Well-Known Member
Licensed User
Longtime User
I use this format to display a date
B4X:
DateTime.DateFormat=" E dd/MM HH:mm:ss "

I live in Italy and the day of week is correctly shown in italian, but after the latest update of my app yesterday, now it is shown in english, not converted to local.

Before: "Ven 28/02 11:21:00"
Now: "Fri 28/02 11:21:00"

Where is the problem ? What is changed ?
 

marcick

Well-Known Member
Licensed User
Longtime User
Yes, I'm not declaring CFBundleLocalizations but Iphone settings are in italian ....
The app is running since 3 years but this change has happened in my last update.
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
I see there is a workaround (need to test it) but really I don't want to force italian language, just let the phone setting to decide. And when the setting are italian I expect to see the week day in italian (as it was working since 3 years).
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
We do not know what is inside DateTime library. But according Erel's post following subroutine changes locale inside DateTime library.

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

As I understand, you want to see the names of days according iPhone UI language.
Stackoverflow recommends

B4X:
NSString * language = [[NSLocale preferredLanguages] firstObject];

Attached example works fine in IOS 13.3 simulator
 

Attachments

  • 111.zip
    1.2 KB · Views: 186
Last edited:
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Thank you Semen,
I have used the above "SetDateTimeLocale ("it")" method. Thinking better this has more sense than rely on the device language.
 
Upvote 0
Top