now.strftime code example
Example 1: python datetime string
import datetime
today = datetime.datetime.now()
date_time = today.strftime("%m/%d/%Y, %H:%M:%S")
print("date and time:",date_time)
Example 2: 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 3: python from timestamp to string
from datetime import datetime
timestamp = 1545730073
dt_object = datetime.fromtimestamp(timestamp)
print("dt_object =", dt_object)
print("type(dt_object) =", type(dt_object))
dt_object = "2018-12-25 09:27:53"
type(dt_object) = <class 'datetime.datetime'>