Is there any way to parse a string like
"Wed Aug 01 01:58:30 GMT 2020"
where GMT can be any possible timezone and then to convert the result of the parsed time to UTC timezone?
When I do
>>> datetime.strptime('Wed Aug 01 01:58:30 GMT 2020', '%a %b %d %H:%M:%S %Z %Y')
datetime.datetime(2020, 8, 1, 1, 58, 30)
I am not getting any timezone information (tzinfo of the returning objet is None). So I am unfortunately already stuck there in the process..
You can use the parse function from dateutil:
from dateutil.parser import parse
parse('Wed Aug 01 01:58:30 GMT 2020')
output: datetime.datetime(2020, 8, 1, 1, 58, 30, tzinfo=tzutc())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With