Datetime.date to Unix timestamp
time.date() is a function that accepts just dates. In this case, 2021 is the year, 8 is the month, and 6 is the day. mktime() is a time method that is the inverse function of local time; it is used to convert dates to Unix timestamps.
Code:
Python3
import datetime import time my_datetime = datetime.date( 2021 , 8 , 6 ) print ( "Unix_Time: " , (time.mktime(my_datetime.timetuple()))) |
Output:
Unix_Time: 1628188200.0
How to Convert DateTime to UNIX Timestamp in Python ?
The Unix timestamp is a single signed integer that grows by one every second, allowing computers to store and manipulate conventional date systems. The software is then translated into a human-readable format. The Unix timestamp is the number of seconds calculated since January 1, 1970. In this article, we are going to see how to convert DateTime to Unix timestamp.