Overview:
-
Given a timestamp from the UNIX epoch i.e., the number of seconds passed since 1970, the class method fromtimestamp() creates a datetime object representing the corresponding local time.
-
If a timezone object or an object of a timezone subclass is provided through tzinfo parameter the timestamp is converted to the time and date of the specific timezone.
-
Leap seconds are ignored by the fromtimestamp() method. In timekeeping the leap seconds are the seconds added often one by one between many years to compensate for the slowing down of Earth’s rotation.
Example:
# Example Python program that creates a import datetime as dt # Create time from timestamp |
Output:
Date and time from the timestamp: |