Open In App
Related Articles

Get current time in milliseconds using Python

Improve Article
Save Article
Like Article

In this article, we will get the time in milliseconds using Python. Here, we are using two inbuild modules of Python that is Datetime module and the Time Module to get the time in milliseconds.

Get time in milliseconds using the DateTime module

To get the time in milliseconds we used the DateTime module, Firstly we printed the date time with seconds. In another line, we printed the milliseconds.


import datetime
dt =
dt.microsecond / 1000


2022-09-20 00:28:51.400420

Get time in milliseconds using the Time module

The time.time() method of the Time module is used to get the time in seconds since the epoch. The handling of leap seconds is platform-dependent.


# Import class time from time module
from time import time
milliseconds = int(time() * 1000)
print("Time in milliseconds since epoch", milliseconds)


Time in milliseconds since epoch 1576071104408

Note: The epoch is the point where the time starts and is platform-dependent. On Windows and most Unix systems, the epoch is January 1, 1970, 00:00:00 (UTC), and leap seconds are not counted towards the time in seconds since the epoch. To check what the epoch is on a given platform we can use time.gmtime(0).

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 30 Sep, 2022
Like Article
Save Article
Similar Reads
Complete Tutorials