Write a Python program to get current time in milliseconds in Python


This program calculates the current timestamp in milliseconds since January 1, 1970 (Unix epoch) using the time module in Python. Here's how it works:

  • The time.time() function returns the current timestamp in seconds since the Unix epoch.
  • This value is multiplied by 1000 to convert it into milliseconds.
  • The round() function is used to round off the result to the nearest integer.
  • Finally, the int() function is used to convert the float value into an integer.

The resulting integer represents the number of milliseconds that have elapsed since the Unix epoch until the current moment.

Source Code

import time
ms = int(round(time.time() * 1000))
print(ms)

Output

1664011145637

Example Programs