Unix timestamps are unreadable to humans, Datetimes are unreadable to machines. Time often needs to converted between Unix and Datetime. I'll demonstrate how you can do that in Python.
Unix to Datetime
import time from datetime import datetime #convert unix to datetime print(datetime.utcfromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S'))
Datetime to Unix
import time from datetime import datetime #convert unix to datetime dtm = datetime.utcfromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') #convert datetime back to unix dtt = datetime.strptime(dtm, '%Y-%m-%d %H:%M:%S') print(datetime.timestamp(dtt))
Top comments (0)