1# Here is a self updating clock function, just run it and it'll self update itself until you hit CTRL-C
2import datetime
3import time
4def clock():
5 while True:
6 print(datetime.datetime.now().strftime("%H:%M:%S"), end="\r")
7 time.sleep(1)
8
9clock()
1>>> from time import perf_counter
2>>> def longrunning_function():
3... for i in range(1, 11):
4... time.sleep(i / i ** 2)
5...
6>>> start = perf_counter()
7>>> longrunning_function()
8>>> end = perf_counter()
9>>> execution_time = (end - start)
10>>> execution_time
118.201258441999926
12
1import time
2seconds = time.time()
3print("Seconds since epoch =", seconds)
4
1>>> strptime('Fri Mar 01 23:38:40 2019')
2time.struct_time(tm_year=2019, tm_mon=3, tm_mday=1, tm_hour=23, tm_min=38, tm_sec=40, tm_wday=4, tm_yday=60, tm_isdst=-1)
3
1>>> from time import strptime
2>>> strptime('2019-03-01', '%Y-%m-%d')
3time.struct_time(tm_year=2019, tm_mon=3, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=4, tm_yday=60, tm_isdst=-1)
4