fork download
  1. from datetime import datetime, timedelta
  2.  
  3. def totimestamp(dt, epoch=datetime(1970,1,1)):
  4. td = dt - epoch
  5. return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 1e6 # td.total_seconds()
  6.  
  7. now = datetime.utcnow()
  8. print now
  9. print totimestamp(now)
Success #stdin #stdout 0.03s 6424KB
stdin
Standard input is empty
stdout
2012-01-08 15:34:10.022403
1326036850.02