Categories
Python Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *