这是我到目前为止所尝试过的。我只是不太确定为什么它输出为 PST 而不是 GMT。我不确定这是否不是解析它或输出它的正确方法。好像有什么地方不对劲。
>>> x = time.strptime('Wed, 27 Oct 2010 22:17:00 GMT', '%a, %d %b %Y %H:%M:%S %Z')
>>> time.strftime('%a, %d %b %Y %H:%M:%S %Z', x)
'Wed, 27 Oct 2010 22:17:00 PST'
感谢任何帮助,
最佳答案
首先我建议您使用 dateutil
>>> import dateutil.parser
>>> x = dateutil.parser.parse('Wed, 27 Oct 2010 22:17:00 GMT')
datetime.datetime(2010, 10, 27, 22, 17, tzinfo=tzutc())
>>> str(x)
'2010-10-27 22:17:00+00:00'
>>> x.strftime('%a, %d %b %Y %H:%M:%S %Z')
'Wed, 27 Oct 2010 22:17:00 UTC'
关于python - 如何从Python中的日期解析时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4038797/