How do I write a string (such as "1284101485") that stores the unix timestamp format in Python?
I thought I could write time.strftime
but I get a TypeError.
import time
print time.strftime("%B %d %Y", "1284101485")
Traceback (most recent call last): File "", line 1, in TypeError: argument must be 9-item sequence, not str
python datetime unix-timestamp strftime
the feature is implemented in datetime.fromtimestamp()/a> module.
import datetime
print(
datetime.datetime.fromtimestamp(
int("1284101485")
).strftime('%Y-%m-%d %H:%M:%S')
)
Result: 2010-09-10 15:51:25
*datetime.datetime.fromtimestamp looks weird, but
© 2024 OneMinuteCode. All rights reserved.