Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Log("Associated time in NY: " & getTimeInNY(1726954050000)) '17:27:30
End Sub
Private Sub getTimeInNY(dt As Long) As String
'get current time offsets in New York (EST-DST)
Dim TimeZoneNY As JavaObject
Dim TimeZoneNYStr As String = TimeZoneNY.InitializeStatic("java.util.TimeZone").RunMethod("getTimeZone", Array("America/New_York")).As(String)
Dim tzParts() As String = Regex.Split("\,", TimeZoneNYStr)
'Just to see what info is available in this time zone structure
' For i = 0 To tzParts.Length - 1
' Log(i & TAB & tzParts(i))
' Next
Dim currentNYOffset As Long = tzParts(1).SubString(tzParts(1).IndexOf("=") + 1)
Dim currentNYDST As Long = tzParts(2).SubString(tzParts(2).IndexOf("=") + 1)
Dim currentNYOffset As Long = (currentNYOffset + currentNYDST) / 3600000
Dim saveLocalOffset As Long = DateTime.TimeZoneOffset
DateTime.SetTimeZone(currentNYOffset)
Dim dtInNY As String = DateTime.Time(dt)
'restore local offset
DateTime.SetTimeZone(saveLocalOffset)
Return dtInNY
End Sub