DateTime to Unix timestamp with 13 digits
To obtain the current time, use datetime.now(). The timetuple() function of the datetime class returns the datetime’s properties as a named tuple. The timestamp with 13 digits must be multiplied by 1000.
Code:
Python3
import time import datetime presentDate = datetime.datetime.now() unix_timestamp = datetime.datetime.timestamp(presentDate) * 1000 print (unix_timestamp) |
Output:
1628497724509.293
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.