Android Question How does Android know what timezone it's in?

App Dude

Active Member
Licensed User
Longtime User
Does it get it from the time it gets through the network, or does it get it from GPS? Or maybe either one that has it?
 

emexes

Expert
Licensed User
Universal time is best from GPS, but I doubt phones actually take their time from that.

For local time, and working out which time zone you're in and what the daylight savings rules are:

Best would be via GSM(-like) mobile phone system, because the cell towers know precisely where they are, and reasonably well where the phones are, and the local time and daylight savings. But not all Android devices are phones with a GSM(-like) connection.

Determining timezone via GPS longitude is a bit iffy, because the time zone lines often wiggle a bit east or west to accommodate what's happening on the ground, eg avoid splitting a city into two time zones, and daylight savings varies more by political borders than by logic.

Determining timezone by IP geolocation is even worse.

Most operating systems synchronize via internet to Network Time Protocol (NTP) servers. The servers are usually super-accurate, and synchronisation is typically within a few milliseconds, depending on how fast packets travel to vs from the server.
 
Last edited:
Upvote 0

App Dude

Active Member
Licensed User
Longtime User
Thanks.
Testing an app I'm working on and that phone does not have a sim card. Went from CST to PST and it does not pick up the new time zone w/GPS on.
I absolutely expected it would get it from the carrier's network, but expected in the absence of that, that it would use GPS, even if not perfect.
Oh well.
 
Upvote 0

emexes

Expert
Licensed User

I admire your optimism ? but I'm guessing it'd still need internet access to determine the time zone from the GPS position, and that the positive karma of non-user-initiated time zone changes getting it right was deemed to be outweighed by the negative karma of when it gets it wrong.

For your own situation, where you know how much or how little perfection is necessary, and if you're working in a known "limited" area, then maybe an approximation of the timezone by longitude would be good enough. Depending on how close you follow those wiggles.



It looks like a GPS Location includes time, and it wouldn't surprise me if that was GPS time (which is UTC time but without the leap seconds since 1980.



This post bodes well for that Time being sourced from GPS :

https://www.b4x.com/android/forum/t...em-date-and-time-through-gps-root-only.73809/
 
Last edited:
Upvote 0

App Dude

Active Member
Licensed User
Longtime User
Makes sense... it would be significant data for the phone to hold to get it correct w/o internet access. And still quite a bit to get it even close.
Not a big deal... I have someone testing an app on a spare no-sim Android phone and he's driving around the US and noticed this oddity. Quicker answer is to connect his Android phone to his iPhone hotspot to sync time periodically.

Fun trivia I learned recently... the SE corner of Oregon (MST) is at the same time as the panhandle of Florida (CST) for one hour per year. That's because in the fall, that part of Florida falls back an hour before that part of Oregon.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…