Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (45.3k 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
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...