Categories
Python Answers

How to use Python strptime() with timezones?

Spread the love

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.

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 *