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
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.
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