Android Question Time zone confusion (like a jetlag)

yeroen

Member
Licensed User
Longtime User
If I use the time zone function <DefTimeZone=DateTime.TimeZoneOffset>
in my app, I get the value 2 in the Netherlands.
For example, if someone uses my app in the USA, will the timezone function show the correct timezone in the USA? If so, then I can simply use the difference in hours in both time zones to adjust my dates and times.
Is this correct, or am I missing another function or lib.
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
Is this correct, or am I missing another function or lib.
Probably neither is correct. You should be doing all of your time and date computation, and saving values in databases, using Android "system" time values (ie UTC). You only need to worry about local time zones when you want to display a DateTime value to the User, and then you do not actually need to worry at all because the DateTime functions will take care of it for you.
B4X:
Log(DateTime.Time(DateTime.Now))
This will display the time according to the local time zone, including any daylight saving time adjustments, anywhere in the world. If the date is an historical date (eg from a time when a different daylight saving adjustment was active) then the appropriate local time will still be displayed.
 
Upvote 0

yeroen

Member
Licensed User
Longtime User
There isn't enough information here. What are you trying to do?

In most cases, adjusting the time zone is a mistake.
Only use B4J now !
The FIFA worldcup football schedule was made in Dutch time (GMT+2).
When you run the app in USA or in Asia the app will adjust all date and time of the schedule to local time.
Look in MainPage at:
Public Sub AdjustTimeZone(NewTimeZone As Float)
Public Sub CheckLeapYear(A1 As Float)
Sub AdjustTimeZoneFunction(inDate As Long, inTime As Float)

I dont know if its correct. Local timezone is measured by DefTimeZone=DateTime.TimeZoneOffset
Public LastTimeZone, DefTimeZone, FileTimeZone As Double
Do you have a snippet, I will test it for you.
Thank you. See reply to Erel.
 

Attachments

  • FootballPredictionWindows.zip
    417.7 KB · Views: 126
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Set up the match timetable in UTC time (Netherlands time minus two hours) and the match times will be shown in local time wherever the app is used - no need for any time zone calculations. Why make it hard for yourself? (B4J or B4A makes no difference, I think).
 
Upvote 0

teddybear

Well-Known Member
Licensed User
I dont know if its correct. Local timezone is measured by DefTimeZone=DateTime.TimeZoneOffset
Public LastTimeZone, DefTimeZone, FileTimeZone As Double
Local timezone is correct, I have tested.

In FIFA_WC_Quatar_2022.fpf file. you should convert datetime string to long by your timezone using DateTimeParse,such as "2022/11/21 15:00:00" it is

1669035600000, Anywhere date & time will be shown correctly
 
Upvote 0

yeroen

Member
Licensed User
Longtime User
Local timezone is correct, I have tested.

In FIFA_WC_Quatar_2022.fpf file. you should convert datetime string to long by your timezone using DateTimeParse,such as "2022/11/21 15:00:00" it is

1669035600000, Anywhere date & time will be shown correctly
Thank you very much for testing.
For some reason i mixed up the Long and Double declarations.
 
Upvote 0
Top