How can I get the timezone time of a location?

Cameron Simpson cs at zip.com.au
Tue Aug 19 19:08:34 EDT 2014


On 18 August 2014 04:28 "luofeiyu" <elearn2014 at gmail.com
>> The land area of China is 60-degree longitude from west to east. According
>to the demarcation of the world time zoning standard,
>> the land area of China lies between the eastern fifth to ninth time zones,
>there are 5 time zones in china in fact.
>> Currently, all the places in China have adopted the eastern eighth time
>zone for the sake of convenience. It is the so-called “Beijing Time”.

Ok, so what we would call "local time" is Beijing Time in all these places.

>> I knew there is a difference between localtime and timezone time.
>> Localtime: The official time in a local region (adjusted for location
>around the Earth); established by law or custom.
>> Timezone: Any of the 24 regions of the globe (loosely divided by longitude)
>throughout which the same standard time is used.
>> Timezone time : If location A is belong to timezone X, the time of timezone
>X is the location A 's timezone time.

No no no.

Firstly, you're taking these definitions as fact. They are just one source.

As a coder, my working definitions go like this:

   local time is the time people use, right now;
     therefore it will be Beijing Time for most people in China

   a time zone is a definition of an offset from GMT, used to compute
     to or from the local time

>> For Urumqi,localtime is the time of east 8 timezone, but timezone time is
>the time of east 6 timezone.

Gah! Your terminaology is causing you trouble.

Urumqi is in a geographical region where, IF THERE WERE NO LEGAL STATUTE IN 
PLACE, the natural choice of local time would be the offset of the "east 6" 
zone. (Ignoring solar time for the moment.)

However, the Chinese government mandates that people work in Beijing Time 
("east 8", yes?) Such arrangements are quite common across the globe, and 
change year to year.

>> How can I get the timezone time of urumqi with python code?

You cannot get it purely from the Olsen timezone database.

The reason for this is that the database is a mapping form timezone names such 
as 'Asia/Urumqi' or 'Australia/Sydney' to GMT offsets, with additional detail 
about summer versus winter time (many places shift their local clocks for part 
of the year) and the time periods when these rules have effect; governments 
change the rules with political whim, and so the db says what the mapping is 
during time spans.

The important point here is the the timezone db is a mapping from timezone name 
to time offsets.

It DOES NOT have any geographical data; there is no way to go from a physcial 
point of the surface of the Earth to the timezone mapping name that should be 
used. (Using only the Olsen timezone db.)

So your code here:

>> tz = pytz.timezone('Asia/Urumqi')

Assumes that 'Asia/Urumqi' is a geographical location. It is not. It is a 
timezone name, in the Olsen db sense of naming a time offset convention. It 
looks like a place name because that is easy to work with.

You also need a mapping from a geographical point to a named timezone rule.

The core question here is: do people in Urumqi set their watches/clocks to 
Beijing time, or do they set their clocks to a more convenient time and just do 
legal things in Beijing time?

And then you need to decide what to use, if these are different.

If the government makes people live and work in Beijing time then probably the 
Olsen db will get an update saying that since that statute came into effect, 
'Asia/Urumqi' has the same offset as Beijing Time.

As Chris says:
>You can't use the Olson tz database (via pytz) for that. The database
>registers legal time and not any of the others. Most people don't really care
>about the other time standards. AFAIK there is no easy solution, you'd have
>to calculate it manually from the longitude, which you'd have to find
>somewhere (online?)

The Olsen db maps a zone name (a physical region usually not shaped like a 
longitude "slice") where a particular legal rule exists for the local time 
offset.

Cheers,
Cameron Simpson <cs at zip.com.au>

Speed costs money.  How fast do you want to go? - C. Shelby



More information about the Python-list mailing list