datetime.datetime obj to hours minute code example

Example 1: 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)

Example 2: python convert datetime.timedelta into seconds

a_timedelta = datetime.timedelta(seconds=24*60*60)

timedelta_seconds = a_timedelta.total_seconds()

print(timedelta_seconds)
OUTPUT
86400.0