datetime isoformat code example

Example 1: python datetime now

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

Example 2: python timedelta

from datetime import timedelta 
tomorrow = datetime.today() + timedelta(days = 1)

Example 3: datetime today

from datetime import datetime

# datetime object containing current date and time
now = datetime.now()
 
print("now =", now)

# dd/mm/YY H:M:S
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
print("date and time =", dt_string)

Example 4: python datetime from timestamp utc

dt_object = datetime.fromtimestamp(timestamp)