0 votes
1 view
in Python by (33.1k points)

I have a Python datetime an object that I want to convert to UNIX time, or seconds/milliseconds since the 1970 epoch.

How do I do this?

1 Answer

0 votes
by (16.8k points)

You can use this:

import datetime

epoch = datetime.datetime.utcfromtimestamp(0)

def unix_time_millis(dt):

    return (dt - epoch).total_seconds() * 1000.0

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...