iOS Question DateTime and locale

Discussion in 'iOS Questions' started by Semen Matusovskiy, May 10, 2019.

  1. Semen Matusovskiy

    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 ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. Semen Matusovskiy

    Semen Matusovskiy Well-Known Member Licensed User

    Thanx for reply. I added a subroutine from your link

    Code:
    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
    Code:
    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: May 13, 2019
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice