Convert (Unix) timestamp seconds to date and time string
The following code snippet illustrates use of
fromtimestamp
to convert unix time-stamp into string. ## # Python's program to convert (Unix) timestamp to date and time string. from datetime import datetime dateStr = datetime.fromtimestamp(1415419007).strftime("%A, %B %d, %Y %I:%M:%S") print(type(dateStr)) print(dateStr)
Sample output of above program.
C:\programs\time>pep8 --first example9.py
C:\programs\time>python example9.py
Saturday, November 08, 2014 09:26:47
C:\programs\time>
C:\programs\time>python example9.py
Saturday, November 08, 2014 09:26:47
C:\programs\time>
2018-03-02T03:12:15+05:30
2018-03-02T03:12:15+05:30
Amit Arora
Amit Arora
Python Programming Tutorial
Python
Practical Solution