Fromtimestamp() Function Of Class In Python

Function Name:


Function Signature:

@classmethod fromtimestamp(timestamp)



timestampThe timestamp for which the date needs to be computed.

Return Value:

Returns the date corresponding to a valid timestamp.

Function Overview:

  • 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.

Exceptions Raised:

OverflowError, OSError           


# ----- Example Python program to get date from timestamp -----

import datetime

import time


# Get date from current time

dateFromCurrentTime =;

print("Date:(Timestamp used is current time):%s"%dateFromCurrentTime);


# Get date from start of unix epoch

dateFromCurrentTime =;

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

Copyright 2020 ©