1
2from datetime import datetime
3
4timestamp = 1528797322
5date_time = datetime.fromtimestamp(timestamp)
6
7print("Date time object:", date_time)
8
9d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
10print("Output 2:", d)
11
12d = date_time.strftime("%d %b, %Y")
13print("Output 3:", d)
14
15d = date_time.strftime("%d %B, %Y")
16print("Output 4:", d)
17
18d = date_time.strftime("%I%p")
19print("Output 5:", d)
20
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