Tuesday, August 23, 2011

python datetime from and to unix timestamp

import datetime
import time

# to timestamp
now = datetime.datetime.now()
time.mktime(now.timetuple())

#from timestamp
datetime.datetime.fromtimestamp(1314066603)

1 comment:

  1. Thanks for this Juan, I was looking for something like this!

    ReplyDelete