syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me

Question:
In Python how do I convert unix-time to datetime?

Let the syntax get a date:
# This script should convert unixtime, in the form of a float,
# into a datetime object.

import datetime

d1970 = datetime.datetime.strptime( '1970-01-01', '%Y-%m-%d' )

unixtime = 59.0

mydate = d1970 + datetime.timedelta(seconds=int(unixtime)) 

print(mydate)


dan@hp /a/ks/b/python $ dan@hp /a/ks/b/python $ python unixtime2datetime.py 1970-01-01 00:00:59 dan@hp /a/ks/b/python $ dan@hp /a/ks/b/python $


syntax.us Let the syntax do the talking
Blog Contact Posts Questions Tags Hire Me