Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/Datetime/Datetime_Convert_timestamp_to_a_datetime_object.ipynb
2973 views
Kernel: Python 3

Datetime.png

Datetime - Convert timestamp to a datetime object

Give Feedback | Bug report

Tags: #datetime #python #timestamp #convert #datetimeobject #library

Last update: 2023-07-05 (Created: 2023-07-05)

Description: This notebook will show how to convert a timestamp to a datetime object in Python.

Input

Import libraries

from datetime import datetime

Setup Variables

  • timestamp: timestamp to be converted to a datetime object

timestamp = 1623456789

Model

Convert timestamp to datetime object

# Convert timestamp to a datetime object datetime_obj = datetime.fromtimestamp(timestamp) datetime_obj

Output

Display result

print(datetime_obj)