Django icalendar dtstart 日期时间问题
Django icalendar dtstart datetime issue
我在 Django 中有一个表单-python 用于事件程序。我正在尝试使用 icalendar 为事件创建一个 ics 文件,为此,我想从变量 'starttime' 和 'endtime' 中获取值 'dtstart' 和 'dtend'的形式,但我得到的代码:错误的日期时间格式。谁有解决这个问题的建议?
错误
elif not ical[15:]:
return datetime(*timetuple)
elif ical[15:16] == 'Z':
return pytz.utc.localize(datetime(*timetuple))
else:
raise ValueError(ical)
except:
raise ValueError('Wrong datetime format: %s' % ical) …
class vDuration(object):
"""Subclass of timedelta that renders itself in the iCalendar DURATION
format.
"""
代码
def event(request, id=None):
instance = Event_cal()
if id:
instance = get_object_or_404(Event_cal, pk=id)
else:
instance = Event_cal()
form = EventForm(request.POST or None, instance=instance)
if request.POST and form.is_valid():
form.save()
startdate = request.POST.get('starttime')
endate = request.POST.get('endtime')
event = Event()
event.add('summary', 'My Summary')
event.add('dtstart', vDatetime.from_ical(startdate))
event.add('dtend', vDatetime.from_ical(endate))
在此先感谢,我正在学习python,所以我没有太多经验。
将日期时间重新格式化为 RFC5545 格式之一。请参阅日期时间格式的 RFC5545 规范说明:https://www.rfc-editor.org/rfc/rfc5545#section-3.3.5.
接受了 3 种日期时间格式:
- 本地或'floating' 例如:19980118T230000
- UTC 时间日期,例如:19980119T070000Z 和
- 具有本地时间和时区参考的日期,例如:
TZID=America/New_York:19980119T020000
我在 Django 中有一个表单-python 用于事件程序。我正在尝试使用 icalendar 为事件创建一个 ics 文件,为此,我想从变量 'starttime' 和 'endtime' 中获取值 'dtstart' 和 'dtend'的形式,但我得到的代码:错误的日期时间格式。谁有解决这个问题的建议?
错误
elif not ical[15:]:
return datetime(*timetuple)
elif ical[15:16] == 'Z':
return pytz.utc.localize(datetime(*timetuple))
else:
raise ValueError(ical)
except:
raise ValueError('Wrong datetime format: %s' % ical) …
class vDuration(object):
"""Subclass of timedelta that renders itself in the iCalendar DURATION
format.
"""
代码
def event(request, id=None):
instance = Event_cal()
if id:
instance = get_object_or_404(Event_cal, pk=id)
else:
instance = Event_cal()
form = EventForm(request.POST or None, instance=instance)
if request.POST and form.is_valid():
form.save()
startdate = request.POST.get('starttime')
endate = request.POST.get('endtime')
event = Event()
event.add('summary', 'My Summary')
event.add('dtstart', vDatetime.from_ical(startdate))
event.add('dtend', vDatetime.from_ical(endate))
在此先感谢,我正在学习python,所以我没有太多经验。
将日期时间重新格式化为 RFC5545 格式之一。请参阅日期时间格式的 RFC5545 规范说明:https://www.rfc-editor.org/rfc/rfc5545#section-3.3.5.
接受了 3 种日期时间格式:
- 本地或'floating' 例如:19980118T230000
- UTC 时间日期,例如:19980119T070000Z 和
- 具有本地时间和时区参考的日期,例如: TZID=America/New_York:19980119T020000