This post will discuss how to get the current time in milliseconds since the Epoch in Python.

1. Using time.time() function

The standard solution to get the current time since the Epoch is using the time.time() function. It returns time in seconds, which can be easily converted into milliseconds, as shown below:

Download  Run Code

 
It returns a floating-point value that can be easily converted to an integer with the int() function.

Download  Run Code

2. Using time.time_ns() function

Starting from Python 3.7, you can use the time.time_ns() function, which is similar to time.time() but returns the total number of nanoseconds since the epoch as an integer.

Download  Run Code

3. Using datetime

Another plausible way is to find the current UTC difference with the Epoch time, i.e., 00:00:00 UTC on 1 January 1970, which returns a timedelta object. To get time in seconds, you can use the timedelta.total_seconds() function.

Download  Run Code

That’s all about getting current time in milliseconds since the epoch in Python.