DateTime to Unix timestamp in UTC Timezone
The calendar module provides helpful calendar-related functions. The utc.now function returns the current time in the UTC timezone. In the time module, the timegm function returns a Unix timestamp. The timetuple() function of the datetime class returns the datetime’s properties as a named tuple. To obtain the Unix timestamp, use print(UTC).
Code:
Python3
import calendar import datetime date = datetime.datetime.utcnow() utc_time = calendar.timegm(date.utctimetuple()) print (utc_time) |
Output:
1628497783
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.