Program to convert timestamp string to date-time object using Python

Introduction

A timestamp value is number of seconds between the current date and date Jan 1,1970 at UTC. The task is to convert the timestamp value to the date object.

Program

from datetime import datetime
output = datetime.fromtimestamp(1546853289)
print("Date and time is:: ", output)

Output

Program to convert timestamp string to date-time object

Explanation

In the above program, we have used python in-built function fromtimestamp() of datetime module. The fromtimestamp() function takes two argument timestamp value and tz (optional argument).

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.