Welcome folks today in this blog post we will be getting the current time of timezone
in python using the pytz
module. All the full source code of the application is shown below.
Get Started
In order to get started you need to install the following library using the pip
command as shown below
pip install pytz
After installing this library you need to make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 |
from datetime import datetime import pytz tz_NY = pytz.timezone('America/New_York') datetime_NY = datetime.now(tz_NY) print("NY time:", datetime_NY.strftime("%H:%M:%S")) tz_London = pytz.timezone('Europe/London') datetime_London = datetime.now(tz_London) print("London time:", datetime_London.strftime("%H:%M:%S")) |
Now if you execute the above python script by typing the below command as shown below
python app.py
Now you can see that we have retrieved the current time
of new york
and london
timezone