How can I get the timezone time of a location?

Chris “Kwpolska” Warrick kwpolska at gmail.com
Mon Aug 18 03:05:21 EDT 2014


On 18 August 2014 04:28 "luofeiyu" <elearn2014 at gmail.com> wrote:
>
> 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”.
>
> 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.

There is also solar time, which is defined as 12:00 = zenith.

> For Urumqi,localtime is the time of east 8 timezone, but timezone time is
the time of east 6 timezone.
> How can I get the timezone time of urumqi with python code?
>
> from datetime import datetime, timedelta
> from pytz import timezone
> import pytz
> tz = pytz.timezone('Asia/Urumqi')
> dt= tz.localize(datetime(2002, 10, 27, 6, 0, 0))
> fmt = '%Y-%m-%d %H:%M:%S %Z%z'
> print(dt.strftime(fmt))
> 2002-10-27 06:00:00 CST+0800
>
> It is a wrong answer,the timezone time is 2002-10-27 04:00:00 +0600
.2002-10-27 06:00:00 CST+0800 is the localtime for Urumiq(by law in china).

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?)
-- 
Chris “Kwpolska” Warrick <http://chriswarrick.com/>
Sent from my SGS3.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140818/2a16b132/attachment.html>


More information about the Python-list mailing list