Convert UTC time to python datetime

流过昼夜 提交于 2019-12-06 04:44:55
Jon Gauthier

Change the year marker in your time format string to %Y:

time = '2012-03-01T00:05:55+00:00'
datetime.strptime(time, "%Y-%m-%dT%H:%M:%S+00:00")
# => datetime.datetime(2012, 3, 1, 0, 5, 55)

See strftime() and strptime() behavior.

I highly recommend python-dateutil library, it allows conversion of multiple datetime formats from raw strings into datetime objects with/without timezone set

>>> from dateutil.parser import parse
>>> parse('2012-04-30T23:08:56+00:00')

datetime.datetime(2012, 4, 30, 23, 8, 56, tzinfo=tzutc())
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!