Json Django日期时间格式谷歌日历
我正试图在谷歌日历中创建一个活动 google api返回此错误: 无效值:无效格式:“2016-02-01T08:00:00-00:00” 我试图正确设置日期格式,但仍然不起作用 这是我的代码:Json Django日期时间格式谷歌日历,json,django,datetime,Json,Django,Datetime,我正试图在谷歌日历中创建一个活动 google api返回此错误: 无效值:无效格式:“2016-02-01T08:00:00-00:00” 我试图正确设置日期格式,但仍然不起作用 这是我的代码: date_s = reservation.date_start.strftime('%Y-%m-%dT%H:%M:%S-00:00') date_e = reservation.date_end.strftime('%Y-%m-%dT%H:%M:%S-00:00') date_star
date_s = reservation.date_start.strftime('%Y-%m-%dT%H:%M:%S-00:00')
date_e = reservation.date_end.strftime('%Y-%m-%dT%H:%M:%S-00:00')
date_start = json.dumps(date_s , cls=DjangoJSONEncoder)
date_end = json.dumps(date_e, cls=DjangoJSONEncoder)
event = {
'summary': summary,
'location': location,
'description': 'A chance to hear more about Google\'s developer products.',
'start': {
'dateTime': date_start,
'timeZone': 'Europe/Paris',
},
'end': {
'dateTime': date_end,
'timeZone': 'Europe/Paris',
}, }
service = build('calendar', 'v3', http=http)
event = service.events().insert(calendarId='primary', body=event).execute()
dateTime
字符串的最后一部分是时区偏移量。问题可能是指定的偏移量与timezone
属性中给定的时区不匹配。文档指定您不需要同时提供这两种格式,因此请尝试仅使用'%Y-%m-%dT%H:%m:%S
作为您的时间格式字符串(该字符串应放入变量中,不得复制)。dateTime字符串的最后一部分是时区偏移量。问题可能是指定的偏移量与timezone
属性中给定的时区不匹配。文档指定您不需要同时提供这两种格式,因此尝试仅使用'%Y-%m-%dT%H:%m:%S
作为您的时间格式字符串(该字符串应放入变量中且不可复制)。您不需要对日期进行json编码,因为您已经将其作为strftime()
产生的字符串,因此json.dumps()
只添加了一对不必要且语法不正确的引号。您不需要对日期进行json编码,因为您已经将日期作为字符串进行编码,这些字符串是由strftime()
产生的,因此json.dumps()
仅添加一对不必要且语法不正确的引号。如果使用date\u s
和date\u e
而不是date\u start
和date\u end
有效吗?如果使用date\u s
和date\u e
而不是date\u start
有效吗?