icalendar是python标准模块
官方文档对时区的数据类型和格式写的不清楚,所以我贴出来供大家参考。
from icalendar import Calendar, Event
from datetime import datetime
import pytz
cal = Calendar()
event = Event()
event.add('summary', "阿狸的课程提醒")
event.add('dtstart', datetime(2021,6,8,6,30,0,tzinfo=pytz.timezone('Asia/Shanghai')))
event.add('dtend', datetime(2021,6,8,7,30,0,tzinfo=pytz.timezone('Asia/Shanghai')))
event.add('description',datetime(2021,6,7,22,30,0,tzinfo=pytz.timezone('Asia/Shanghai')))
event.add('location', "一号教学楼")
cal.add_component(event)
with open('C:/Users/Administrator/Desktop/测试.ics',mode='wb')as file:
file.write(cal.to_ical())
print("日程文件生成成功!")
觉得好点个赞