Menu Close

How to parse dates with -0400 time zone string in Python?

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 use the dateutil library.

To install it, we run

pip install python-dateutil

Then we use it by writing

from dateutil.parser import parse
d = parse('2022/05/13 19:19:30 -0400')

to call parse with the datetime string with the time zone to return a datetime object with the time zone offset set.

Conclusion

To parse dates with -0400 time zone string in Python, we use the dateutil library.

Posted in Python, Python Answers