daniel-s
4/7/2016 - 3:13 PM

Python datetimes, timestamps, UNIX, posix

Python datetimes, timestamps, UNIX, posix

import time
from datetime import datetime


now = datetime.utcnow() # Timezone naive (no timezone info at all)

print(now) 
# 2016-04-07 14:33:33.184000

print(now.isoformat()) 
# 2016-04-07T14:33:33.184000

now_posix = time.mktime(now.timetuple()) + now.microsecond * 0.000001

print(now_posix)
# 1460036013.18

now_again = datetime.fromtimestamp(now_posix)

print(now_again)
# 2016-04-07 14:33:33.184000