Skip to content

Instantly share code, notes, and snippets.

@wonkoderverstaendige
Created February 11, 2016 01:11
Show Gist options
  • Save wonkoderverstaendige/39961960a91c844cdbcb to your computer and use it in GitHub Desktop.
Save wonkoderverstaendige/39961960a91c844cdbcb to your computer and use it in GitHub Desktop.
Unix time stamp and back
import datetime
import time
dt = datetime.datetime.now()
# datetime.datetime(2016, 2, 11, 2, 8, 51, 160960)
du = time.mktime(dt.timetuple()) + dt.microsecond*1e-6
# 1455152931.16096
dt2 = datetime.datetime.utcfromtimestamp(du)
# datetime.datetime(2016, 2, 11, 1, 8, 51, 160960)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment