3

我有这个代码:

$event = new Event();
$event->setSummary( $_event['summary'] );
$event->setLocation( $_event['location'] );
$start = new EventDateTime();
$start->allDay = true;
$start->setDateTime($_event['start']);
$event->setStart($start);
$cal->events->insert( $_calendar['id'], $event  );

但不起作用=\

任何的想法?

4

1 回答 1

11

如果您想创建一个为期一天的事件,请使用 $start->setDate() 而不是 $start->setDateTime()。

创建一个为期一天的活动

$event = new Event();
$event->setSummary("Summary of the event");
$event->setLocation("Location");

$start = new EventDateTime();
$start->setDate("2013-01-01"); 
$event->start=$start;

$end = new EventDateTime();
$end->setDate("2013-01-02");
$event->end=$end;

$calendarId="primary"; // primary represents your calendar
$createdEvent = $cal->events->insert($calendarId, $event);

在给定的持续时间内创建事件

$event = new Event();
$event->setSummary("Summary of the event");
$event->setLocation("Location");

$start = new EventDateTime();
$start->setDateTime("2013-01-01T0:00:00.000+00:00");
$event->start=$start;

$end = new EventDateTime();
$end->setDateTime("2013-01-01T0:01:00.000+00:00");
$event->end=$end;

$calendarId="primary";
$createdEvent = $cal->events->insert($calendarId, $event);
于 2013-03-19T03:20:56.450 回答