具有 "+00"时区偏移格式的 Python strptime?

标签 python date time timezone

如何解析格式为 +00 的时区偏移量? Python 3 或 Python 2

from datetime import datetime
s = '2019-04-10 21:49:41.607472+00'
# What must I replace <XX> with, to parse +00 as the timezone offset
d = datetime.strptime(s, '%Y-%m-%d %H:%M:%S.%f<XX>')

最佳答案

您可以使用 dateutil's parse为此:

from dateutil.parser import parse
s = '2019-04-10 21:49:41.607472+00'
parse(s)

datetime.datetime(2019, 4, 10, 21, 49, 41, 607472, tzinfo=tzutc())

关于具有 "+00"时区偏移格式的 Python strptime?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55639481/

相关文章:

python - Django : value too long for type character varying(30) when input not even 10 characters

python - 如何在已由 scrapy 下载的网页上使用 selenium.PhantomJS()

javascript - 在 Angular Js 中选择日期后,不要丢失 Rzslider 的先前位置?

java 日历格式

sql - PostgreSQL - 逐秒创建 View

c++ - 将 ptime 转换为 std::string

python - 如何限制正则表达式中出现的某些字符

python - 图像处理概要

java - 在纪元中转换日期格式

php - Joomla 中的日期转换为用户时区