Android Question Problem with Timezones

FrankBerra

Active Member
Licensed User
Longtime User
Hi all
I am playing with Timezones: I want to show a time-label changing it's time based on the Timezone.
I am using this really simple example:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    DateTime.SetTimeZone(DateTime.TimeZoneOffset)
    Activity.LoadLayout("Layout1")
    Dim data As String = "1496441223000"
    Label1.Text= DateTime.Date(data) & " - " & DateTime.Time(data)
End Sub

I am expecting thant when i change the timezone in Android settings and i open the app again the Label1.Text changes accordingly.
The strange fact is that it works only one time, that means if i change again the TimeZone in android settings the Label1.Text doesn't change anymore.
If i kill the app and open it again it works for just one TimeZone's change.

Anyone that can explain why this is happening?

Thanks in advance
 

aaronk

Well-Known Member
Licensed User
Longtime User
Try:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then DateTime.ListenToExternalTimeChanges
End Sub

Sub Activity_Resume

    DateTime.SetTimeZone(DateTime.TimeZoneOffset)
    Activity.LoadLayout("Layout1")
    Dim data As String = "1496441223000"
    Label1.Text= DateTime.Date(data) & " - " & DateTime.Time(data)

End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…