iOS Question Set TimeZone

Discussion in 'iOS Questions' started by MotoMusher, Feb 15, 2015.

  1. MotoMusher

    MotoMusher Active Member Licensed User

    Working on Moving a B4A app to B4i.

    I was using reflector to set the timezone in B4A:
    Code:
    Public Sub SetTimeZone(id As String)
      
    Dim r As Reflector
      
    ' Dim r As NativeObject
       Dim idTz As Object = r.RunStaticMethod("java.util.TimeZone""getTimeZone"Array As String(id), _
         
    Array As String("java.lang.String"))
       r.RunStaticMethod(
    "anywheresoftware.b4a.keywords.DateTime""setTimeZoneInternal", _
         
    Array As Object(idTz), Array As String("java.util.TimeZone"))
    End Sub
    Is there a better way to do this in B4i?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    What exactly are you trying to do? Why do you need to change the time zone?
     
  3. MotoMusher

    MotoMusher Active Member Licensed User

    My existing B4A app creates an encoded token based on US Pacific time, which has to match functionality of an existing website/internal applications which I was asked to duplicate in apps. I can do settimezone -8 with b4i, but that doesn't account for dst.

    I can hardcode around dates, at least for now if there is no equivalent. B4a solution was elegant.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Here:
    Code:
    Private Sub Application_Start (Nav As NavigationController)
       NavControl = Nav
       Page1.Initialize(
    "Page1")
       Page1.RootPanel.Color = 
    Colors.White
       NavControl.ShowPage(Page1)
       PrintKnownTimeZones
       SetTimeZone(
    "Pacific/Tahiti")
       
    Log(DateTime.GetTimeZoneOffsetAt(DateTime.Now))
    End Sub

    Sub SetTimeZone(id As String)
       
    Dim no As NativeObject
       no.Initialize(
    "NSTimeZone")
       no.RunMethod(
    "setDefaultTimeZone:", _
         
    Array(no.RunMethod("timeZoneWithName:"Array(id))))
    End Sub

    Sub PrintKnownTimeZones
       
    Dim no As NativeObject
       no.Initialize(
    "NSTimeZone")
       
    Dim timeZones As List = no.RunMethod("knownTimeZoneNames"Null)
       
    For Each s As String In timeZones
         
    Log(s)
       
    Next
    End Sub
     
    MotoMusher likes this.
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