timezone - 谷歌日历在日历的时区中包含 timeMin 的事件列表
问题描述
要求
我可以在此参考之后检索 google-calendar 事件列表:https ://developers.google.com/calendar/v3/reference/events/list
如何根据日历的 timeZone2017-03-30T14:30:00
获取所有事件的列表?2017-03-30T15:30:00
我的调查
有可选参数timeMin
, timeMax
。问题是它们应该具有以下格式之一(RFC3339 时间戳):
2017-03-30T14:30:00Z
, 这里Z
代表 Zulu = UTC timeZone2017-03-30T14:30:00+03
, 这里+03
代表与 UTC 相比的时区偏移
在这两种情况下,我都必须获取日历的时区(如何以我需要的偏移格式获取它,例如,、、?-04
),然后执行一些额外的计算/操作。+00
+03
显然,在我的情况下,我宁愿只传递值而不提及时区,并使 API 使用日历的时区。
还有另一个可选参数timeZone
,但这是将在响应中使用的 timeZone,而不是在过滤器中。默认是日历的时区,这对我有好处。
解决方案
最后我找到了在日期时间应用 GC (Google Calendar) TZ 的方法:
from dateutil import tz
from datetime import datetime
tzinfo = tz.gettz(default_calendar['timeZone'])
# Option1: create date without TZ and then apply GC TZ using astimezone:
dt = datetime(2018,7,3,14,30,0)
dt_in_gc_tz = dt.astimezone(tzinfo) # 2018-07-03 14:30:00+03:00
# Option2: just create dateTime with GC TZ:
dt_in_gc_tz = datetime(2018, 7,3,14,30,0, tzinfo=tzinfo) # 2018-07-03 14:30:00+03:00
# Convert to RFC3339 timestamp string:
dt_in_gc_tz.isoformat() # '2018-07-03T14:30:00+03:00'
推荐阅读
- python - 在mpld3中如何使红线可拖动?
- flutter - 颤振:如何在聊天消息的右下角对齐时间
- react-admin - React admin导入按钮referenceManyField?
- python - 使用 Seaborn `displot`(不是 `distplot`)在同一图表上绘制多个直方图
- r - 从命令行渲染 R markdown。Bash 脚本中的错误 - 没有这样的文件或目录
- c++ - 从文本文件中读取字符串和浮点数
- javascript - MongoClient 的 findOne() 永远不会在 Electron 上解析,即使填充了集合
- .net - Dapper 查询 ToList 为 IEnumerable
> 结果为空 - java - 使用java搜索文本文件以查找所有以“ing”结尾的单词
- java - 如何在不知道数组大小的情况下初始化数组