I have the following string format:
date = 'Jun 8, 2021 PDT'
I'm trying to convert that string into a datetime
object. Right now I have it at:
dt_o = dt.strptime(date, '%b %d, %Y')
That gets me almost all the way there, but I am still getting the following error:
ValueError: unconverted data remains: PDT
Is there a way to include the 'PDT'
in the original creation of the datetime
object?. My other option is to strip the string of the 'PDT'
and create a timezone unaware object.
dt_o = dt.strptime(date.rsplit(None, 1)[0], '%b %d, %Y')
gives me an object of: datetime.datetime(2021, 6, 8, 0, 0)
.
is there a way I can apply the PDT
timezone to that? I'd need to be able to convert it from the string date.rsplit(None, 1)[1]
, since it won't always be PDT