How To Get The Time! ⏰ [python]
here is a tutorial for adding the time of multiple cities in your programs, using
I have included two versions; one of them where you have to manually change it in the code, and another where you ask the user!
from datetime import datetime import pytz tz_city = pytz.timezone('country/city') # replace 'country' and 'city' with your choice # for cities with two words, add an underscore in between them datetime_city = datetime.now(tz_city) # prints the time, in hours, minutes, and seconds. print("Time:", datetime_city.strftime("%H:%M:%S"))
the second method is a bit more complex, its the repl attached below. there are many comments to guide you.
- a input to ask the user the continent/city of their choice
- tells you if its
- has an error message if the user puts a typo/not existing/etc. (using
anyways, if you have any questions, please ask them and I will
try to answer them.
feel free to comment suggestions, tips, chatter, etc.
And if it helped you, Upvoting is Caring! ;)
Have a super-duper day!
disclaimer: not all cities are displayed, but many are (major cities, capitals, high population, etc.)
and oceania doesnt work :/
Surprisingly accurate! (Note the time in the bottom left corner)
time.time()is an option
Hey bookie! Nice post! I do have one small complaint though, could you calm down on the y's a tiny bit? Its a little troublesome when AllAwesome497's bot auto reports this for spam when you do that. Thanks in advance! (Also interesting use of datetime)