<p><code>-0600</code>是格林尼治标准时间(GMT)的偏移量。作为<a href="https://stackoverflow.com/questions/9959778/is-there-a-wildcard-format-directive-for-strptime">another SO question already says</a>,time.strtime无法读取时区偏移,尽管<code>datetime.strftime</code>可以生成它们。</p>
<p>正如在<a href="https://stackoverflow.com/questions/9959778/is-there-a-wildcard-format-directive-for-strptime">the ^{<cd3>} module's documentation</a>开头所解释的,python中有两种接近“时间”的方式,天真的或有意识的。当您只关心系统中的时间<em>时,处理纯时间/日期时间对象就可以了(在这种情况下,您可以按照alan的建议去掉偏移量)。当您需要将系统中的值与现实世界中的时间概念进行比较时,您必须开始处理这个偏移量。</p>
<p>处理这个问题的简单方法就是<a href="http://docs.python.org/library/datetime.html#module-datetime" rel="nofollow noreferrer">use ^{<cd4>}</a>。它有一个<a href="http://labix.org/python-dateutil#head-c0e81a473b647dfa787dc11e8c69557ec2c3ecd2" rel="nofollow noreferrer">parse function</a>尽其所能模糊地匹配您传入的多格式日期字符串,并返回一个可行的datetime实例,该实例表示对您的意思的最佳猜测。</p>
<pre><code>>>> from dateutil.parser import parse
>>> parse('17/Dec/2011:09:48:49 -0600', fuzzy=True)
datetime.datetime(2011, 12, 17, 9, 48, 49, tzinfo=tzoffset(None, -21600))
</code></pre>
<p>通常,让软件给出“最佳猜测”是件坏事。在这种情况下,如果您的输入格式是稳定的,这似乎是合理的。在软件开发中处理时间是很困难的,只是去购物。</p>