bar*_*lou 2 php google-calendar-api
我正在使用带有 PHP 的 Google 日历 api V3,并试图获取事件的摘要、描述和开始日期。我的问题是最后一个元素:开始日期。当日历中的事件设置为“全天”事件时,来自以下代码的响应为我提供了今天的日期和进行查询的确切时间:
echo "<div id=Activite class=titre>", $event->getSummary(), "</div>\n";
$event_date = (new DateTime($event->getStart()->getDateTime()))->format('d/m/Y H:i');
echo "<div class=date_start><span style=color:yellow;>Start: </span>", $event_date, "</div>\n";
Run Code Online (Sandbox Code Playgroud)
以下是返回内容的示例:
prise de photos des élèves
Start: 22/11/2014 18:30
Run Code Online (Sandbox Code Playgroud)
从“Google APIs Explorer”读取相同的输出,我得到:
start": {
"date": "2013-09-13"
Run Code Online (Sandbox Code Playgroud)
这与我在我的情况下得到的完全不同。我究竟做错了什么?
好吧,这是答案。经过“ippi”的大力建议,我了解到谷歌对一个事件使用了 2 个不同的变量:开始...“日期”/“日期时间”。对我有用的代码是这样的工作,它使代码能够识别它是否正在处理全天事件:
if (($event->getStart()->getDate())!= NULL) {
$event_date = (new DateTime($event->getStart()->getDate()))->format('d/m/Y');
} else {
$event_date = (new DateTime($event->getStart()->getDateTime()))->format('d/m/Y H:i');
}
Run Code Online (Sandbox Code Playgroud)