Another application that I have no control over returns datetime values as Jan 1, 2019 09:00:00.000 X-0500. The X preceeding the timezone is driving me bonker since I cannot find out how to ignore it. Without the X, this works:
from datetime import datetime
datetime.strptime('Jan 1, 2019 09:00:00.000 -0500', '%b %d, %Y %H:%M:%S.%f %z')
I can manually remove the X but is there a way to write the format string such that Python treats the X as a literal X with no special meaning?
datetime.strptime('Jan 1, 2019 09:00:00.000 X-0500', '???')
Just write a literal X in the format string:
datetime.strptime('Jan 1, 2019 09:00:00.000 X-0500', '%b %d, %Y %H:%M:%S.%f X%z')
^
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