DateTime to Unix timestamp milliseconds
The datetime.now() function is used to obtain the current time. The mktime method is a time method that is the inverse function of local time; it is used to convert datetime to Unix timestamp milliseconds. The timetuple() function of the datetime class returns the datetime’s properties as a named tuple. To obtain the time in milliseconds, multiply it by 1000.
Code:
Python3
import datetime import time ms = datetime.datetime.now() print (time.mktime(ms.timetuple()) * 1000 ) |
Output:
1628497823000.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.