Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python strtime加上+;00“;时区偏移格式?_Python_Date_Time_Timezone - Fatal编程技术网

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”是格式错误的指令