nad
nad

Reputation: 2850

Google Calendar API retrieving datetime

I need to retrieve datetime info from Google Calendar API. I am looking into this quickstart example. It retrieves start time of the meeting in a string format.

for event in events:
        start = event['start'].get('dateTime', event['start'].get('date'))
        print(start, event['summary'])

How can I retrieve the time in datetime format, not in a string format. So I can extract out year, month, hour, minute etc. information.

EDIT: An example output from the above statement

2018-03-07T13:00:00-08:00

Upvotes: 1

Views: 1234

Answers (1)

Tanaike
Tanaike

Reputation: 201378

How about using dateutil? I think that there may be other methods. So please think of this as one of them.

Modified script :

import dateutil.parser

for event in events:
        start = event['start'].get('dateTime', event['start'].get('date'))
        parsedDate = dateutil.parser.parse(start)
        print(parsedDate, event['summary'])

Reference :

If I misunderstand your question, I'm sorry.

Upvotes: 1

Related Questions