Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
3

Find current time in your region using Python.

OldWizard209
OldWizard209

So first import datetime:
from datetime import datetime

Then import pytz and import timezone:
from pytz import timezone

Then you can do this:

tz = timezone("US/Eastern") date = datetime.now(tz) print("Current date and time: ") print(date.strftime("%Y-%m-%d %H:%M:%S"))

So I have set the timezone to US/Eastern. There are specific codes for timezones. You can find them here

or if you want import it yourself:

import pytz for tz in pytz.all_timezones: print(tz)

Hope this helps y'all

2 years ago

Voters

Comments

TopNew
1
Sky-Boyko
Sky-Boyko

for some reason it is working on here but when i copy the code onto a new repl is is giving me a "No module named 'pytz'" error, do you know how to fix this?

9 months ago
1
OldWizard209
OldWizard209

you have to import pytz first.

@Sky-Boyko

9 months ago
1

Good job :)

2 years ago
Load more