I'm trying to do something really simple, convert a datetime
object three days into the future into a Unix UTC timestamp:
import datetime, time
then = datetime.datetime.now() + datetime.timedelta(days=3)
# Method 1
print then.strftime("%s")
# Method 2
print time.mktime(then.timetuple())
# Method 3
print time.mktime(then.timetuple()) * 1000
Method 1 and 2 give me Unix time in seconds, not milliseconds, and method 3 gives me milliseconds with no actual millisecond precision.
When I simply print then
, I get datetime.datetime(2011, 11, 19, 15, 16, 8, 278271)
, so I know that the precision is available for milliseconds. How can I get a Unix timestamp with actual millisecond precision? If it's returned as a float and I have to flatten it to an an int
, that's fine. Is there a solution I'm looking for that does this?