0 votes
1 view
in Python by (1.6k points)

I have a string representing a unix timestamp (i.e. "1284101485") in Python, and I'd like to convert it to a readable date. When I use time.strftime, I get a TypeError:

>>>import time

>>>print time.strftime("%B %d %Y", "1284101485")

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

TypeError: argument must be 9-item sequence, not str

1 Answer

0 votes
by (25.1k points)
edited by

You can use the datetime module.

from datetime import datetime

ts = int("1284101485")

print(datetime.utcfromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !