Get current time in milliseconds in Python?

StackOverflow

How can I get the current time in milliseconds in Python?

Answer rating: 860

Using time.time():

import time

def current_milli_time():
    return round(time.time() * 1000)

Then:

>>> current_milli_time()
1378761833768

Answer rating: 95

From version 3.7 you can use time.time_ns() to get time as passed nano seconds from epoch. So you can do

ms = time.time_ns() // 1_000_000 

to get time in mili-seconds as integer.





Get Solution for free from DataCamp guru