Categories
Python Answers

How to get a value of datetime.today() in Python that is time zone aware?

Spread the love

Sometimes, we want to get a value of datetime.today() in Python that is time zone aware.

In this article, we’ll look at how to get a value of datetime.today() in Python that is time zone aware.

How to get a value of datetime.today() in Python that is time zone aware?

To get a value of datetime.today() in Python that is time zone aware, we can use the pytz module.

For instance, we write

import pytz
from datetime import datetime

utc_now = datetime.now(pytz.utc)

to call datetime.now with pytz.utc to get the current datetime in UTC.

Conclusion

To get a value of datetime.today() in Python that is time zone aware, we can use the pytz 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 *