Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to use the same tool to have Ubuntu guess what timezone it is currently in?

This article mentions the feature I'm looking for (just above the second pic):

share|improve this question
Unfortunately, only one of those questions had an actionable/appropriate answer. I guess 64 is better than 55, but I can select answers just for the sake of improving that. – Bryan Agee Jun 22 '12 at 8:16
Many thanks, Brian. When you have a chance, could you perhaps add comments to those questions/answers as to whats missing, increasing the chances that a good answer will show up in the future? – izx Jun 22 '12 at 8:20
Thanks for the tips--as I have time, I'll go through and update them. – Bryan Agee Jun 22 '12 at 9:06

Ubuntu uses the ubuntu-geoip package, which queries

You can python-geoip to achieve the same thing:

import GeoIP
geo =
ip = ''
print geo.country_code_by_addr(ip)

Sadly, it doesn't work with ipv6 yet.

share|improve this answer
I was really hoping that someone might know where that bit of code lives, and if it might be called again.... – Bryan Agee Jun 22 '12 at 9:07
I found the exact query to get xml: wget -O - -q – Bryan Agee Jun 22 '12 at 9:28
up vote 1 down vote accepted

I decided to download the ubiquity source and dig for it. Greping timezone found the concerned lines, which issue the command:

wget -O - -q

and parse the resulting xml.

Rather than load up python or something else, I just wrote a quick bash script that grabs the xml and yanks the timezone out with sed:


# Fetch timezone from Ubuntu's geoip server
TZ=`wget -O - -q | sed -n -e 's/.*<TimeZone>\(.*\)<\/TimeZone>.*/\1/p'`

# Set the current time
cp /usr/share/zoneinfo/$TZ /etc/localtime
share|improve this answer
Will that work? I thought /etc/localtime was a binary file? Sure you don't need to do this: – Jason Livesay Feb 3 '14 at 8:13
Yep; the above code works like a charm, and has been in production for a couple years now. – Bryan Agee Aug 7 '14 at 2:13
I'm in Melbourne, Australia, and doing this query from my IP address gives me CountryCode=AU, CountryName=Australia, TimeZone=None. So it deduces the country successfully, but not the timezone within the country. – Craig McQueen Oct 12 '15 at 6:38

I believe that it uses your internet connection & ip address to find that information. When I have installed offline it always asks you to select a timezone.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.