为什么Google日历全天活动使用php返回今天的开始日期 [英] why Google Calendar all day events return start date as today with php

查看:53
本文介绍了为什么Google日历全天活动使用php返回今天的开始日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Google Calendar api V3与PHP结合使用,并试图获取事件的摘要,描述和开始日期.我的问题是最后一个要素:开始日期.当日历中的事件设置为全天"事件时,以下代码的响应将为我提供今天的日期和进行查询的确切时间:

I am using Google calendar api V3 with PHP and am trying to get event's summary, description and start date. My issue is with the last element: Start date. When events in the calendar are set as "All day" events, the response from the following code gives me today's date and the exact time when the query was made:

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

以下是返回内容的示例:

Here is an example of what is returned:

prise de photos des élèves
Start: 22/11/2014 18:30

从"Google APIs Explorer"中读取相同的输出,我得到:

Reading the same output from the "Google APIs Explorer", I get:

start": {
"date": "2013-09-13"

这与我的情况完全不同.我在做什么错了?

Which is nothing like what I am getting in my case. What am I doing wrong?

推荐答案

嗯,这就是答案.在获得"ippi"的大力建议后,我了解到Google为事件使用了2个不同的变量:start ..."Date"/"DateTime".对我有用的代码是围绕该代码的工作,使代码能够识别它是否正在处理一整天的事件:

Well, here goes for the answer. After great advise by "ippi", I got to understand that Google uses 2 different variables for an event: start... "Date" / "DateTime". The code that worked for me is this work around that enabled the code to recognize if it was dealing with an all day event or not:

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');
}

这篇关于为什么Google日历全天活动使用php返回今天的开始日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆