timestamp – The timestamp for which the date needs to be computed.
Returns the date corresponding to a valid timestamp.
The method fromtimestamp() of the date class computes the date corresponding to a given timestamp and returns it. Methods like time.time() can be used get a timestamp.
- The supported timestamp range is from the year 1970 to the year 2038.
- The fromtimestamp() method does not consider leap seconds if any present in the timestamp.
- The method fromtimestamp() is a class method.
# ----- Example Python program to get date from timestamp -----
# Get date from current time
dateFromCurrentTime = datetime.date.fromtimestamp(time.time());
print("Date:(Timestamp used is current time):%s"%dateFromCurrentTime);
# Get date from start of unix epoch
dateFromCurrentTime = datetime.date.fromtimestamp(0);
print("Date:(Timestamp used is Unix Epoch time):%s"%dateFromCurrentTime);
Date:(Timestamp used is current time):2019-07-12
Date:(Timestamp used is Unix Epoch time):1970-01-01