iOS Question Set TimeZone

MotoMusher

Active Member
Licensed User
Working on Moving a B4A app to B4i.

I was using reflector to set the timezone in B4A:
B4X:
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?
 

MotoMusher

Active Member
Licensed User
What exactly are you trying to do? Why do you need to change the time zone?
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.
 

Erel

Administrator
Staff member
Licensed User
Here:
B4X:
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
 
Top