Python 3.x 如何在太平洋时区使用谷歌日历API获取我今天的所有活动
我正在尝试使用谷歌日历API从一天的开始到一天的结束提取所有每日事件。我使用API遵循google的quickstart程序,但它给了我接下来的10个事件以及UTC时区的0偏移量。我只想抓拍当天和“美国/洛杉矶”时区的活动Python 3.x 如何在太平洋时区使用谷歌日历API获取我今天的所有活动,python-3.x,google-calendar-api,Python 3.x,Google Calendar Api,我正在尝试使用谷歌日历API从一天的开始到一天的结束提取所有每日事件。我使用API遵循google的quickstart程序,但它给了我接下来的10个事件以及UTC时区的0偏移量。我只想抓拍当天和“美国/洛杉矶”时区的活动 now = datetime.datetime.utcnow().isoformat() + 'Z' print('Getting todays events') events_results = service.events().list(calen
now = datetime.datetime.utcnow().isoformat() + 'Z'
print('Getting todays events')
events_results = service.events().list(calendarId='primary', timeMin=now,
maxResults=10, singleEvents=True,
orderBy='startTime').execute()
您可以对脚本进行以下更改:
today = datetime.datetime.today();
start = (datetime.datetime(today.year, today.month, today.day, 00, 00)).isoformat() + 'Z'
tomorrow = today + datetime.timedelta(days=1)
end = (datetime.datetime(tomorrow.year, tomorrow.month, tomorrow.day, 00, 00)).isoformat() + 'Z'
print('Getting todays events')
events_results = service.events().list(calendarId='primary', timeMin=start, timeMax=end, singleEvents=True, orderBy='startTime').execute()
如果要从今天检索所有事件,必须使用timeMin
和timeMax
参数。timeMin
将设置为今天的日期小时00:00
,而timeMax
则表示这一天的结束-因此选择了使用00:00
设置的明天日期
此外,此处不需要maxResults
参数,因为您希望检索所有事件,而不是有限的数量
请记住,为时间最小值
和时间最大值
提供的日期都是独占边界,它们必须是带有强制时区偏移的RFC3339时间戳
对于将来的请求,您还可以使用来模拟它们并测试所需的参数
参考文献
- )