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)
ZnJvbSBkYXRldGltZSBpbXBvcnQgZGF0ZXRpbWUsIHRpbWVkZWx0YQoKZGVmIHRvdGltZXN0YW1wKGR0LCBlcG9jaD1kYXRldGltZSgxOTcwLDEsMSkpOgogICAgdGQgPSBkdCAtIGVwb2NoCiAgICByZXR1cm4gKHRkLm1pY3Jvc2Vjb25kcyArICh0ZC5zZWNvbmRzICsgdGQuZGF5cyAqIDI0ICogMzYwMCkgKiAxMCoqNikgLyAxZTYgIyB0ZC50b3RhbF9zZWNvbmRzKCkKCm5vdyA9IGRhdGV0aW1lLnV0Y25vdygpCnByaW50IG5vdwpwcmludCB0b3RpbWVzdGFtcChub3cp