Python时间与正确的格式不匹配

Pro*_*eus 0 python

我有以下字符串:

2016-04-29T00:00:00 + 01:00

我想使用Python将其转换为Unix日期时间戳.

我试过这个把它转换成日期对象:

dt = datetime.datetime.strptime(validated_data.get('scheduled_datetime', None), '%Y-%m-%dT%H:%M:%SZ')
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

time data '2016-04-29T00:00:00+01:00' does not match format '%Y-%m-%dT%H:%M:%S'
Run Code Online (Sandbox Code Playgroud)

小智 5

2016-04-29T00:00:00+01:00
Run Code Online (Sandbox Code Playgroud)

不是一种strptime可以理解的形式.它支持

%z UTC偏移量,格式为+ HHMM或-HHMM

但请注意,:时区中没有冒号!

因此,首先:从输入中删除冒号然后使用%z.