How to Convert TimeStamp String to DateTime Object in Python?

The time.strftime() function automatically adds the current time to a string according to the format. Now that you know how to convert time stamp string to date time object in Python, you can use this simple code in your program. If you are planning to develop a program which needs to display dates, then this code example will help you:

convert timestamp to datetime

By Concerned CheetahConcerned Cheetah on May 19, 2020
from datetime import datetime

timestamp = 1545730073
dt_object = datetime.fromtimestamp(timestamp)

print("dt_object =", dt_object)
print("type(dt_object) =", type(dt_object))

Source: www.programiz.com

Add Comment

2

convert timestamp to datetime

By Concerned CheetahConcerned Cheetah on May 19, 2020
from datetime import datetime

# current date and time
now = datetime.now()

timestamp = datetime.timestamp(now)
print("timestamp =", timestamp)

Source: www.programiz.com

Add Comment

0

It adds the time to your string using the format of your choice and returns an instance of the DateTime object.

Python answers related to "convert timestamp to datetime"

View All Python queries

Python queries related to "convert timestamp to datetime"

Browse Other Code Languages

CodeProZone