python datetime.fromtimestamp code example

Example 1: python datetime now

import datetime
print(datetime.datetime.now()) #datetime.datetime.now() is the syntax

Example 2: timestamp 1601825400 in python

from datetime import datetime

timestamp = 1545730073
dt_object = datetime.fromtimestamp(timestamp)

print("dt_object =", dt_object)
print("type(dt_object) =", type(dt_object))

Example 3: python datetime

from datetime import date
f_date = date(2014, 7, 2)
l_date = date(2014, 7, 11)
delta = l_date - f_date
print(delta.days)

Example 4: python datetime from timestamp utc

dt_object = datetime.fromtimestamp(timestamp)