Menu Close

How to use Python strptime() with timezones?

Sometimes, we want to use Python strptime() with timezones.

In this article, we’ll look at how to use Python strptime() with timezones.

How to use Python strptime() with timezones?

To use Python strptime() with timezones, we can use dateutil.

To install it, we run

pip install python-dateutil

Then we use it by writing

from dateutil import parser
d = parser.parse("Tue Jun 22 07:46:22 EST 2022")

to call parser.parse with the datetime string with the time zone.

Conclusion

To use Python strptime() with timezones, we can use dateutil.

Posted in Python, Python Answers