为什么centos系统的pytz.country_timezones('cn')结果不一样?
why pytz.country_timezones('cn') in centos system have different result?
两台电脑安装centos 6.5,内核是3.10.44,结果不同。
一个结果是[u'Asia/Shanghai', u'Asia/Urumqi']
,另一个是['Asia/Shanghai', 'Asia/Harbin', 'Asia/Chongqing', 'Asia/Urumqi', 'Asia/Kashgar']
.
是否有任何配置使第一个结果与第二个结果相同?
我有以下 python 代码:
def get_date():
date = datetime.utcnow()
from_zone = pytz.timezone("UTC")
to_zone = pytz.timezone("Asia/Urumqi")
date = from_zone.localize(date)
date = date.astimezone(to_zone)
return date
def get_curr_time_stamp():
date = get_date()
stamp = time.mktime(date.timetuple())
return stamp
cur_time = get_curr_time_stamp()
print "1", time.strftime("%Y %m %d %H:%M:%S", time.localtime(time.time()))
print "2", time.strftime("%Y %m %d %H:%M:%S", time.localtime(cur_time))
使用此代码获取时间时,一台电脑(有2个结果)的结果为:
1 2016 04 20 08:53:18
2 2016 04 20 06:53:18
另一个(有 5 个结果)是:
1 2016 04 20 08:53:18
2 2016 04 20 08:53:18
不知道为什么?
您的系统上可能只有一个过时的 pytz 版本,返回五个时区(或者可能在两个系统上)。您可以找到最新版本 here。掌握时区更新非常重要,因为世界各国政府经常更改时区。
与大多数系统一样,pytz 从 tz database. The five time zones for China were reduced to two in version 2014f (corresponding to pytz 2014.6). From the release notes:
获取数据
China's five zones have been simplified to two, since the post-1970
differences in the other three seem to have been imaginary. The
zones Asia/Harbin, Asia/Chongqing, and Asia/Kashgar have been
removed; backwards-compatibility links still work, albeit with
different behaviors for time stamps before May 1980. Asia/Urumqi's
1980 transition to UTC+8 has been removed, so that it is now at
UTC+6 and not UTC+8. (Thanks to Luther Ma and to Alois Treindl;
Treindl sent helpful translations of two papers by Guo Qingsheng.)
此外,您不妨阅读维基百科的 Time in China 文章,其中解释了 Asia/Urumqui
条目是指“乌鲁木齐时间”,在新疆地区的某些地区非正式使用。该区域不被中国政府承认,被认为是一个充满政治色彩的问题。因此,许多系统选择省略乌鲁木齐时区,尽管它在 tz 数据库中列出。
两台电脑安装centos 6.5,内核是3.10.44,结果不同。
一个结果是[u'Asia/Shanghai', u'Asia/Urumqi']
,另一个是['Asia/Shanghai', 'Asia/Harbin', 'Asia/Chongqing', 'Asia/Urumqi', 'Asia/Kashgar']
.
是否有任何配置使第一个结果与第二个结果相同?
我有以下 python 代码:
def get_date():
date = datetime.utcnow()
from_zone = pytz.timezone("UTC")
to_zone = pytz.timezone("Asia/Urumqi")
date = from_zone.localize(date)
date = date.astimezone(to_zone)
return date
def get_curr_time_stamp():
date = get_date()
stamp = time.mktime(date.timetuple())
return stamp
cur_time = get_curr_time_stamp()
print "1", time.strftime("%Y %m %d %H:%M:%S", time.localtime(time.time()))
print "2", time.strftime("%Y %m %d %H:%M:%S", time.localtime(cur_time))
使用此代码获取时间时,一台电脑(有2个结果)的结果为:
1 2016 04 20 08:53:18
2 2016 04 20 06:53:18
另一个(有 5 个结果)是:
1 2016 04 20 08:53:18
2 2016 04 20 08:53:18
不知道为什么?
您的系统上可能只有一个过时的 pytz 版本,返回五个时区(或者可能在两个系统上)。您可以找到最新版本 here。掌握时区更新非常重要,因为世界各国政府经常更改时区。
与大多数系统一样,pytz 从 tz database. The five time zones for China were reduced to two in version 2014f (corresponding to pytz 2014.6). From the release notes:
获取数据China's five zones have been simplified to two, since the post-1970 differences in the other three seem to have been imaginary. The zones Asia/Harbin, Asia/Chongqing, and Asia/Kashgar have been removed; backwards-compatibility links still work, albeit with different behaviors for time stamps before May 1980. Asia/Urumqi's 1980 transition to UTC+8 has been removed, so that it is now at UTC+6 and not UTC+8. (Thanks to Luther Ma and to Alois Treindl; Treindl sent helpful translations of two papers by Guo Qingsheng.)
此外,您不妨阅读维基百科的 Time in China 文章,其中解释了 Asia/Urumqui
条目是指“乌鲁木齐时间”,在新疆地区的某些地区非正式使用。该区域不被中国政府承认,被认为是一个充满政治色彩的问题。因此,许多系统选择省略乌鲁木齐时区,尽管它在 tz 数据库中列出。