near_me
Linear Algebra
keyboard_arrow_down 54 guides
chevron_leftDocumentation
check_circle
Mark as learned thumb_up
0
thumb_down
0
chat_bubble_outline
0
Comment auto_stories Bi-column layout
settings
Python Datetime | fromtimestamp method
schedule Aug 12, 2023
Last updated local_offer
Tags Python
tocTable of Contents
expand_more Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!
Start your free 7-days trial now!
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?
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
Official Python Documentation
https://docs.python.org/3/library/datetime.html#datetime.date.fromtimestamp
thumb_up
0
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!