To convert a datetime object to UNIX timestamp in python, we can use the timestamp() method. The timestamp() method, when invoked on a datetime object, returns the UNIX epoch for the given datetime object. You can observe this in the following example.
from datetime import datetime datetime_obj=datetime.today() print("The datetime object is:") print(datetime_obj) epoch=datetime_obj.timestamp() print("The epoch is:") print(epoch).