fromtimestamp() Function Of Datetime.date Class In Python
The fromtimestamp() function is used to return the date corresponding to a specified timestamp.
Note: Here the timestamp is ranging from the year 1970 to the year 2038, and this function does not consider leap seconds if any present in the timestamp. This function is a class method.
Syntax: @classmethod fromtimestamp(timestamp)
Parameters: This function accepts a parameter which is illustrated below:
- timestamp: This is the specified timestamp for which the date is going to be returned.
Return values: This function returns the date corresponding to a specified timestamp.
Example 1: Getting a date corresponding to an Epoch & Unix Timestamp.
Python3
import datetime
import time
Todays_time = time.time()
print (Todays_time)
date_From_CurrentTime = datetime.date.fromtimestamp(Todays_time);
print ( "Date for the Timestamp is: %s" % date_From_CurrentTime);
|
Output:
1627279008.95
Date for the Timestamp is: 2021-07-26
Example 2: Getting a date corresponding to a specified timestamp.
Python3
import datetime
import time
Timestamp = 1323456464 ;
date_From_Timestamp = datetime.date.fromtimestamp(Timestamp);
print ( "Date for the Timestamp is: %s" % date_From_Timestamp);
|
Output:
Date for the Timestamp is: 2011-12-09
Last Updated :
28 Jul, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...