from datetime import datetime now = datetime.now() # current date and time year = now.strftime("%Y") print("year:", year) month = now.strftime("%m") print("month:", month) day = now.strftime("%d") print("day:", day) time = now.strftime("%H:%M:%S") print("time:", time) date_time = now.strftime("%m/%d/%Y, %H:%M:%S") print("date and time:",date_time) 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) from datetime import datetime timestamp = 1528797322 date_time = datetime.fromtimestamp(timestamp) d = date_time.strftime("%c") print("Output 1:", d) d = date_time.strftime("%x") print("Output 2:", d) d = date_time.strftime("%X") print("Output 3:", d)