epoch = datetime.datetime.utcfromtimestamp(0)

def unix_time_millis(dt):
    return (dt - epoch).total_seconds() * 1000.0
How can I convert a datetime object to milliseconds since epoch (unix time) in Python?