相关疑难解决方法(0)

如何在python中识别未知的日期时区时区

我需要做什么

我有一个时区不知道的日期时间对象,我需要添加一个时区,以便能够将其与其他时区感知日期时间对象进行比较.我不想将我的整个应用程序转换为时区,而不是因为这个遗留案例.

我试过的

首先,要证明问题:

Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> import pytz
>>> unaware = datetime.datetime(2011,8,15,8,15,12,0)
>>> unaware
datetime.datetime(2011, 8, 15, 8, 15, 12)
>>> aware = datetime.datetime(2011,8,15,8,15,12,0,pytz.UTC)
>>> aware
datetime.datetime(2011, 8, 15, 8, 15, 12, tzinfo=<UTC>)
>>> aware == unaware
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't compare offset-naive and offset-aware …
Run Code Online (Sandbox Code Playgroud)

python timezone datetime

446
推荐指数
10
解决办法
27万
查看次数

标签 统计

datetime ×1

python ×1

timezone ×1