Convert Unix timestamp string to readable date in Python
Example 1: Convert the specified Unix timestamp string.
Python3
# Importing datetime module import datetime # Calling the fromtimestamp() function to # extract datetime from the given timestamp # Calling the strftime() function to convert # the extracted datetime into its string format print (datetime.datetime.fromtimestamp( int ( "1294113662" )) .strftime( '%Y-%m-%d %H:%M:%S' )) |
Output:
2011-01-04 09:31:02
Example 2: Convert the specified Unix timestamp string.
Python3
# Importing datetime module import datetime # Calling the fromtimestamp() function to # extract datetime from the given timestamp timestamp = datetime.datetime.fromtimestamp( 1200001234 ) # Calling the strftime() function to convert # the extracted datetime into its string format print (timestamp.strftime( '%Y-%m-%d %H:%M:%S' )) |
Output:
2008-01-11 03:10:34
Python program to convert unix timestamp string to readable date
In this article, we are going to see the conversion of the Unix timestamp string to a readable date. This can be done with the help of fromtimestamp() and strftime() functions in Python.
Example:
Input: 1294113662 Output: 2011-01-04 09:31:02 Explanation: Unix timestamp string to a readable date