本文介绍了Django icalendar dtstart datetime问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Django-python中有一个用于事件程序的表单.我正在尝试为具有icalendar的事件创建一个ics文件,为此,我想从表单中的变量"starttime"和"endtime"中获取值"dtstart"和"dtend",但是代码:错误的日期时间格式.有人对解决此问题有任何建议吗?

I have a form in Django-python for an event program. I'm trying to create an ics file for the events with icalendar, for this, I want to get the values 'dtstart' and 'dtend' from the variables 'starttime' and 'endtime' in the form, but I'm getting the code: Wrong datetime format. Anyone with any advice to solve this issue?

错误

            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.
    """

CODE

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,所以我没有太多经验.

Thanks in advance, I am learning python, so I don't have have much experience.

推荐答案

将日期时间重新格式化为RFC5545格式之一.请参阅有关日期时间格式的RFC5545规范说明: https://tools.ietf.org/html/rfc5545#section-3.3.5 .

Reformat the date times into one of the RFC5545 formats. Please see the RFC5545 specifications instructions for the datetime formats: https://tools.ietf.org/html/rfc5545#section-3.3.5.

有3种可接受的日期时间格式:

There are 3 accepted datetime formats:

  1. 本地或浮动",例如:19980118T230000
  2. 具有UTC时间的日期,例如:19980119T070000Z和
  3. 具有本地时间和时区参考的日期,例如:TZID =美国/纽约:19980119T020000

这篇关于Django icalendar dtstart datetime问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 01:59
查看更多