简体   繁体   中英

How get startdate in Google Calendar API v3 PHP

Because Google shutted down the other API, I have to re-write my code for v3 API.

I think it is simple but I cannot make it.

I want to get the Start date of every event in my timespan. But how?

I've this code till now:

$start = date(DateTime::ATOM, mktime(0,0,0,date('m'), date('d'), date('Y')));
$end = date(DateTime::ATOM, mktime(23,59,59,12, 31, 2025));

$eventOptions = array("orderBy"=>"startTime",
                  "singleEvents"=>true,
                  "timeMin"=>$start,
                  "timeMax"=>$end);
$events = $service->events->listEvents($calName, $eventOptions);


foreach ($events->getItems() as $event) {
echo $event->getSummary(); //GET TITLE OF EVENT
echo "<br>";
echo $event->getLocation(); //GET LOCATION OF EVENT

// WHAT TO PLACE HERE TO ECHO THE DATE OF THE EVENT?

echo "<br>**------**<br>";
}

I'm getting crazy of this 'simple' thing. Who can help me?

I believe...to get the datetime of the event:

$event->getStart()->dateTime

For just the date:

$event->getStart()->date

You can use the "Resource Representations" found here: https://developers.google.com/google-apps/calendar/v3/reference/events to see all the different event data. Scroll down to:

 "start": {
    "date": date,
    "dateTime": datetime,
    "timeZone": string
  },

and it should make sense.

You can output the data by:

echo $event->start->dateTime.' - '.$event->end->dateTime;

For full output of $event object use :

vardump($event);

hope that helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM