python starttime time.time() code example

Example 1: how to record execution time in python

import time

start = time.time()
print("hello")
end = time.time()
print(end - start)

Example 2: python how to measure code run in time

import time
start_time = time.time()
main()
print("--- %s seconds ---" % (time.time() - start_time))

Example 3: time.strftime

from datetime import datetime

timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)

print("Date time object:", date_time)

d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)	

d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)

d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)

d = date_time.strftime("%I%p")
print("Output 5:", d)