Python strtime加上+;00“;时区偏移格式?
如何解析格式为Python strtime加上+;00“;时区偏移格式?,python,date,time,timezone,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>') 从日期时间导入日期时间 s='
+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>')
从日期时间导入日期时间
s='2019-04-1021:49:41.607472+00'
#要将+00解析为时区偏移量,我必须替换什么
d=datetime.strTime(s,“%Y-%m-%d%H:%m:%s.%f”)
您可以使用:
from dateutil.parser import parse
s = '2019-04-10 21:49:41.607472+00'
parse(s)
datetime.datetime(2019,4,10,21,49,41607472,tzinfo=tzutc())
strtime
使用%z
指定UTC偏移量,格式为±HHMM[SS[.ffffff]]
。由于分钟是必需的,并且示例输入只有小时,因此可以在解析之前将'00'
连接到字符串:
datetime.strptime(s + '00', '%Y-%m-%d %H:%M:%S.%f%z')
Python2.7说,
***ValueError:“z”是格式错误的指令