Get current time in milliseconds using Python

Time module in Python provides various time-related functions. This module comes under Python’s standard utility modules, so there is no need to install it externally.

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

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).

Syntax: time.time()

Return type: This method returns a float value which represents the time in seconds since the epoch.



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to get
# time in milliseconds
  
# Import class time from time module
from time import time
  
# time() function is multiplied with 
# 1000 to convert seconds into milliseconds.
milliseconds = int(time() * 1000)
  
print("Time in milliseconds since epoch", milliseconds)

chevron_right


Output:

Time in milliseconds since epoch 1576071104408

Example 2: Using lambda function

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to get
# time in milliseconds
  
  
# Import class time from time module
from time import time
  
# Get time in milliseconds using
# lambda function
milliseconds = lambda: int(time() * 1000)
  
print("Time in milliseconds since epoch", milliseconds())

chevron_right


Output:

Time in milliseconds since epoch 1576071316487
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.