David
David

Reputation: 3056

How do parse a time with changing timezones

I need to parse the following time:

 mytime = "11:32  PM LT"
 datetime.strptime(mytime,  '%H:%M %p LT')

But sometimes "11:32 PM LT" is a GMT time like for example "18:32 PM GMT". How do I parse that correctly so both time types are taken into consideration?

Upvotes: 0

Views: 38

Answers (1)

Stanton
Stanton

Reputation: 495

Please try the dateutil package.

parse('11:32  PM GMT')
datetime.datetime(2019, 6, 26, 23, 32, tzinfo=tzutc())

Upvotes: 1

Related Questions