python


Current Time

We can get current time from datetime module



from datetime import datetime

now = datetime.now()

current_time = now.strftime("%H:%M:%S")
print("Current Time =", current_time)
                


We can get time using Time Module also



import time

t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
print(current_time)

Timezone

pytZ module is used to findcurrent time of a certain timezone


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"))