Sometimes, we want to parse dates with -0400 time zone string in Python.
In this article, we’ll look at how to parse dates with -0400 time zone string in Python.
How to parse dates with -0400 time zone string in Python?
To parse dates with -0400 time zone string in Python, we can use the dateutil.parser
module.
For instance, we write:
from dateutil.parser import parse
d = parse('2020/05/13 19:19:30 -0400')
print(d)
We call parse
with the date string including the time zone.
And then we assign the returned result to d
.
Therefore, d
is '2020-05-13 19:19:30-04:00'
.
Conclusion
To parse dates with -0400 time zone string in Python, we can use the dateutil.parser
module.