chevron_left
Documentation
0
0
0
new
Python Datetime | fromtimestamp method
Programming
chevron_rightPython
chevron_rightStandard Library
chevron_rightDatetime
chevron_rightDocumentation
schedule Mar 10, 2022
Last updated Python
Tags tocTable of Contents
expand_more Python’s date.fromtimestamp(~)
method converts a Unix timestamp to a date
object.
NOTE
A Unix timestamp is the number of seconds between a particular date and January 1, 1970 UTC.
Parameters
1. timestamp
| Unix timestamp
The Unix timestamp to convert to corresponding date
object.
Return value
A date
object based off the provided Unix timestamp.
Examples
To return date
object from Unix timestamp 1476561252
:
from datetime import date timestamp = date.fromtimestamp(1476561252)print(timestamp)print(type(timestamp))
2016-10-16<class 'datetime.date'>
To return date
object from current Unix timestamp:
import datetimeimport time
timestamp = time.time()print(timestamp)
date_object = date.fromtimestamp(timestamp)print(date_object)
1610854011.178642021-01-17
Published by Arthur Yanagisawa
Edited by 0 others
Did you find this page useful?
Ask a question or leave a feedback...
Official Python Documentation
https://docs.python.org/3/library/datetime.html#datetime.date.fromtimestamp