Reputation: 2850
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
Reputation: 201378
How about using dateutil
? I think that there may be other methods. So please think of this as one of them.
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'])
If I misunderstand your question, I'm sorry.
Upvotes: 1