fork download
from datetime import datetime, timedelta

def totimestamp(dt, epoch=datetime(1970,1,1)):
    td = dt - epoch
    return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 1e6 # td.total_seconds()

now = datetime.utcnow()
print now
print totimestamp(now)
Success #stdin #stdout 0.03s 6424KB
stdin
Standard input is empty
stdout
2012-01-08 15:34:10.022403
1326036850.02