Joshua Siraj
Joshua Siraj

Reputation: 15

how would I parse this with datetime(python)

{'dateTime': '2020-12-31T08:00:00-05:00'}

my attempt:

start = "{'dateTime': '2020-12-31T08:00:00-05:00'}"
start_obj = datetime.datetime.strptime(start, "{'dateTime': '%Y-%m-%dT%I:%M:%S-05:00'}"
print(start_obj)

Upvotes: 0

Views: 79

Answers (1)

Nanthakumar J J
Nanthakumar J J

Reputation: 911

import datetime

dates = {'dateTime': '2020-12-31T08:00:00-05:00'}
start_obj = datetime.datetime.strptime(dates['dateTime'], "%Y-%m-%dT%I:%M:%S%z")
print(start_obj)

Upvotes: 1

Related Questions