Using time.time():

import time

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

Then:

>>> current_milli_time()
1378761833768
Answer from Naftuli Kay on Stack Overflow
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ datetime.html
datetime โ€” Basic date and time types
'milliseconds': Include full time, but truncate fractional second part to milliseconds. HH:MM:SS.sss format. 'microseconds': Include full time in HH:MM:SS.ffffff format. ... Excluded time components are truncated, not rounded.
Discussions

python - Format a datetime into a string with milliseconds - Stack Overflow
In Python 3.11 (maybe older version support it too) it can be done with isoformat(timespec='milliseconds') ... The optional argument timespec specifies the number of additional terms of the time to include. Valid options are 'auto', 'hours', 'minutes', 'seconds', 'milliseconds' and 'microseconds'. >>> datetime.now... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Convert python datetime to timestamp in milliseconds - Stack Overflow
How do I convert a human-readable time such as 20.12.2016 09:38:42,76 to a Unix timestamp in milliseconds? More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to get min, seconds and milliseconds from datetime.now() in python? - Stack Overflow
In that case, if you don't mind ... calling datetime.now() redundant but I don't think there is a time difference in the three different function calls. Please correct me if I am wrong. 2012-03-23T19:23:38.513Z+00:00 ... Yes, I know I didn't get the string formatting perfect. ... what about method strftime() .... I just can't figure out the parameter for milliseconds ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How can I convert a datetime object to milliseconds since epoch (unix time) in Python? - Stack Overflow
I have a Python datetime object that I want to convert to unix time, or seconds/milliseconds since the 1970 epoch. How do I do this? More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-to-get-min-seconds-and-milliseconds-from-datetime-now-in-python
How to get min, seconds and milliseconds from datetime.now() in Python?
2 weeks ago - Today's date is: 2024-01-15 14:25:42.378945 Minutes: 25 Seconds: 42 Microseconds: 378945 Milliseconds: 378 ยท Here we use the strftime() method, which is provided by the datetime module.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ get-current-time-in-milliseconds-using-python
Get current time in milliseconds using Python - GeeksforGeeks
July 12, 2025 - 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)
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-use-strptime-with-milliseconds-in-python
How to use strptime with milliseconds in Python - GeeksforGeeks
July 23, 2025 - Here's how to do it: ... from datetime ... = datetime.strptime(s, format) print(dt_obj) ... Use %f when you want to include milliseconds or microseconds in your datetime string. In this example, we convert a string with milliseconds ...
๐ŸŒ
CodeRivers
coderivers.org โ€บ blog โ€บ get-current-time-python-milliseconds
Getting the Current Time in Python with Milliseconds - CodeRivers
April 9, 2025 - Access the microsecond attribute of the datetime object and divide it by 1000 to get the milliseconds. We also multiply the second part by 1000 and add the milliseconds to get the total milliseconds since the start of the minute. When measuring the performance of a piece of code, getting the ...
๐ŸŒ
Statistics Globe
statisticsglobe.com โ€บ home โ€บ python programming language for statistics & data science โ€บ convert datetime into string with milliseconds in python (3 examples)
Convert datetime into String with Milliseconds in Python (3 Examples)
January 26, 2023 - On this site, youโ€™ll learn how to convert a datetime object into string with milliseconds in the Python programming language. ... Letโ€™s dive into it! In this example we are going to use the datetime module.
Find elsewhere
๐ŸŒ
EnableGeek
enablegeek.com โ€บ home โ€บ obtain python current time in milliseconds
Obtain Python Current Time in Milliseconds - EnableGeek
March 21, 2024 - import datetime current_datetime = datetime.datetime.now() print(current_datetime) This will print the current date and time in the format โ€˜YYYY-MM-DD HH:MM:SS.ssssssโ€˜. In Python, you can get the current time in milliseconds using the โ€˜timeโ€˜ ...
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ date-time-exercise โ€บ python-date-time-exercise-12.php
Python: Get current time in milliseconds - w3resource
July 22, 2025 - Finally it prints the value stored in 'milli_sec', which represents the current time in milliseconds since the epoch. ... Write a Python program to fetch the current time and then display it in milliseconds since the epoch.
๐ŸŒ
Esri Community
community.esri.com โ€บ t5 โ€บ python-questions โ€บ milliseconds-with-strftime โ€บ td-p โ€บ 73258
Solved: Milliseconds with strftime - Esri Community
December 10, 2021 - (I can appended i at the end of new Time as a phony millisecond...) That should just about do it.... Solved! Go to Solution. ... from datetime import datetime curr_time = datetime.now() formatted_time = curr_time.strftime('%H:%M:%S.%f') print(formatted_time) 18:41:59.891075โ€โ€โ€โ€โ€โ€...
๐ŸŒ
Iditect
iditect.com โ€บ faq โ€บ python โ€บ format-a-datetime-into-a-string-with-milliseconds-in-python.html
Format a datetime into a string with milliseconds in python
To include milliseconds, you can ... # Create a datetime object with milliseconds now = datetime.now() # Format the datetime with milliseconds formatted_datetime = now.strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] print(formatted_datetime)...
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ python-add-milliseconds-to-datetime
How to add Milliseconds to Datetime in Python | bobbyhadz
Copied!from datetime import datetime, ... '%Y-%m-%d %H:%M:%S.%f') print(dt) # ๐Ÿ‘‰๏ธ 2023-11-24 09:30:00.000123 result = dt + timedelta(milliseconds=300) print(result) # ๐Ÿ‘‰๏ธ 2023-11-24 09:30:00.300123 ......
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ python โ€บ python datetime milliseconds
How to Convert DateTime to String With Milliseconds in Python | Delft Stack
February 2, 2024 - Python provides a straightforward ... # Convert to string with milliseconds formatted_datetime = current_datetime.strftime("%Y-%m-%d %H:%M:%S.%f")[:-3] print(formatted_datetime)...
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ 5 best ways to get milliseconds in python
5 Best Ways to Get Milliseconds in Python - Be on the Right Side of Change
February 27, 2024 - This provides the time since the epoch as a floating point number, which can then be converted to milliseconds. ... from datetime import datetime timestamp_millis = int(datetime.now().timestamp() * 1000) print(timestamp_millis)
๐ŸŒ
py4u
py4u.org โ€บ blog โ€บ python-time-milli-seconds-calculation
How to Calculate Milliseconds in Python Using datetime Module: A Practical Guide
To get the current time in milliseconds, start by fetching the current datetime object with datetime.now(), then extract its microsecond attribute and convert to milliseconds.
๐ŸŒ
Bomberbot
bomberbot.com โ€บ python โ€บ mastering-python-time-the-ultimate-guide-to-getting-current-time-in-milliseconds
Mastering Python Time: The Ultimate Guide to Getting Current Time in Milliseconds - Bomberbot
This method uses datetime.now() to get the current date and time, then converts it to a timestamp and multiplies by 1000. The advantage of this approach is that it allows for easy manipulation of the datetime object before converting to milliseconds, which can be useful in more complex scenarios.