suh*_*lvs 4 python timezone datetime python-datetime
我对 dateformat 有一些疑问Tue Feb 25 2014 00:00:00 GMT+0530 (IST)。
Tue Feb 25 2014 00:00:00意味着GMT或ISTdatetime。DD-MM-YY,HH:MM:SSGMT 格式。这是我尝试转换成的内容python datetime::
但当我尝试使用时出现错误%z:
>>> time_format="%a %b %d %Y %H:%M:%S GMT%z (%Z)"
>>> v="Tue Feb 25 2014 00:00:00 GMT+0530 (IST)"
>>> mydate=datetime.strptime(v,time_format)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/_strptime.py", line 317, in _strptime
(bad_directive, format))
ValueError: 'z' is a bad directive in format '%a %b %d %Y %H:%M:%S GMT%z (%Z)'
Run Code Online (Sandbox Code Playgroud)
但这有效:
>>> time_format="%a %b %d %Y %H:%M:%S GMT (%Z)"
>>> v="Tue Feb 25 2014 00:00:00 GMT (IST)"
>>> datetime.strptime(v,time_format)
datetime.datetime(2014, 2, 25, 0, 0)
Run Code Online (Sandbox Code Playgroud)
但仍然不明白任何事情TIMEZONE。
在系统终端中
easy_install python-dateutil
Run Code Online (Sandbox Code Playgroud)
在 python shell 中
from dateutil import parser as date_parser
print date_parser.parse("Tue Feb 25 2014 00:00:00 GMT+0530 (IST)")
Run Code Online (Sandbox Code Playgroud)
Dateutil 的解析通常可以将您扔给它的任何内容解析为 Python 日期时间。
| 归档时间: |
|
| 查看次数: |
6602 次 |
| 最近记录: |