PyDocs

Nav

Data Types

date.fromtimestamp

datetime

classmethod of date
  • date.fromtimestamp(timestamp)
Create a date from a POSIX timestamp.

The timestamp is a number, e.g. created via time.time(), that is
interpreted as local time.
Changed in 3.3, 3.15
  • 3.3: Raise OverflowError instead of ValueError if the timestamp is out of the range of values supported by the platform C localtime() function. Raise OSError instead of ValueError on localtime() failure.
  • 3.15: Accepts any real number as timestamp, not only integer or float.
1 Example
>>> import time
>>> import datetime as dt
>>> today = dt.date.today()
>>> today
datetime.date(2007, 12, 5)
>>> today == dt.date.fromtimestamp(time.time())
True
>>> my_birthday = dt.date(today.year, 6, 24)
>>> if my_birthday < today:
...     my_birthday = my_birthday.replace(year=today.year + 1)
...
>>> my_birthday
datetime.date(2008, 6, 24)
>>> time_to_birthday = abs(my_birthday - today)
>>> time_to_birthday.days
202
from the Python docs
See Also
No see-alsos for datetime/date.fromtimestamp
0 Notes
No notes for date.fromtimestamp