Android Question Change my Database time to target different timezones

tamba sylvester

Member
Licensed User
Longtime User
I have a time that is set in the Database.
I need help in making the time differ from different timezones depending on where the app user is.
I need this in my android application.
Thanks
 

emexes

Expert
Licensed User
I need help in making the time differ from different timezones depending on where the app user is.

Can you give some examples of what you'd like to happen?

Eg do you want "School starts at 9:00" to display the same to your app users everywhere?

Or do you want "The webinar starts at 11:00" to display as your app users' local time?

as in: if I wanted to watch a webcast from San Francisco that advertises a start time of 7am, then it would be rather useful if it also mentioned that in my timezone (Melbourne, Australia) it will be starting at 12 midnight.
 
Upvote 0

emexes

Expert
Licensed User
Or are you printing flight itineraries, where ideally the flight takeoff and landing times should all be the local airport time ie the time shown on a wall clock at the airport?

Eg I can't reasonably say to somebody in Amsterdam meeting my son off a flight, that the flight's landing 3am Melbourne time.

Correction: I could, but the odds of a consequent cock-up would be > 50%
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
If you are storing times for multiple time zones then the DB server should always be set to UTC. You should also store any time values as UTC.

Never set the DB servers time zone to local time zone and never store times as local times.
 
Upvote 0

tamba sylvester

Member
Licensed User
Longtime User
If you are storing times for multiple time zones then the DB server should always be set to UTC. You should also store any time values as UTC.

Never set the DB servers time zone to local time zone and never store times as local times.
Is it possible to save in one timezone and have it change on phone depending on local timezone.
That is what I want to achieve
Thanks
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Test Example:
B4X:
    DateTime.DateFormat = "yyyy-MM-dd H:mm:ss"
    
'    Get TimeZona Device
    Dim DeviceTimeZona As Double = DateTime.TimeZoneOffset
    
'    DateTimeZone UTC Example Database
    DateTime.SetTimeZone(0)    
    Log("DateTime In Database: " & DateTime.Date(DateTime.Now))

'    DateTimeZone Device
    DateTime.SetTimeZone(DeviceTimeZona)
    Log("DateTime In Device: "  & DateTime.Date(DateTime.Now))
1664532777798.png
 
Upvote 0

Chris2

Active Member
Licensed User
Longtime User
Is it possible to save in one timezone and have it change on phone depending on local timezone.
Yes.

I'd suggest you first take a look at the Date & Time Video tutorial.
As @tchart said, store the times as UTC in the DB (where ever they are set from), either as strings, DateTime data types, or (probably easiest) ticks.

When you convert ticks to a string with DateTime.Date or DateTime.Time, the string returned is in the local device time zone.
 
Upvote 0

Shelby

Well-Known Member
Licensed User
Longtime User
Or are you printing flight itineraries, where ideally the flight takeoff and landing times should all be the local airport time ie the time shown on a wall clock at the airport?

Eg I can't reasonably say to somebody in Amsterdam meeting my son off a flight, that the flight's landing 3am Melbourne time.

Correction: I could, but the odds of a consequent cock-up would be > 50%
Cock-up??
Oddly, in British English it is not these days a vulgarism, or at least only a very mild one. It comes from one of several senses of cock, to bend at an angle, as in — for example — cocking a gun or turning up the brim of one’s headgear (so producing an old-time naval officer’s cocked hat).

The use of cock-up to mean a blunder or error was originally British military slang dating from the 1920s. The slang sense of cock clearly had a lot to do with its adoption, but this hasn’t stopped it being used in respectable publications, and modern British dictionaries mark it merely as informal or colloquial.
 
Upvote 0

emexes

Expert
Licensed User
Cock-up??

Oddly, in British English it is not these days a vulgarism, or at least only a very mild one. It comes from one of several senses of cock, to bend at an angle, as in — for example — cocking a gun or turning up the brim of one’s headgear (so producing an old-time naval officer’s cocked hat).

The use of cock-up to mean a blunder or error was originally British military slang dating from the 1920s. The slang sense of cock clearly had a lot to do with its adoption, but this hasn’t stopped it being used in respectable publications, and modern British dictionaries mark it merely as informal or colloquial.

Regionality of words is a topic ripe with titbits ?
 
Upvote 0

emexes

Expert
Licensed User
making the time differ from different timezones depending on where the app user is.
in my android application.

Just out of interest: how's this project going?

Any interim screenshots?

Dare we ask what your decision was re: storing times in your database? (no worries if you sidestep reopening that can of worms ? )

?
 
Upvote 0
Top