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 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.

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 *