🌐
Python
docs.python.org › 3 › library › time.html
time — Time access and conversions
The epoch is the point where the time starts, the return value of time.gmtime(0).
🌐
Real Python
realpython.com › python-time-module
A Beginner’s Guide to the Python time Module – Real Python
October 21, 2023 - First, time.time() returns the number of seconds that have passed since the epoch. The return value is a floating point number to account for fractional seconds: ... The number you get on your machine may be very different because the reference ...
🌐
Programiz
programiz.com › python-programming › datetime › current-time
Python Get Current time (With Examples)
Using datetime.strftime() function, we then created a string representing current time. In Python, we can also get the current time using the time module.
🌐
Tutorialspoint
tutorialspoint.com › python › time_time.htm
Python time time() Method
The Python time time() method returns the current UTC time. This return value is obtained as a floating point number expressed in seconds since the epoch. This method does not accept any arguments, hence, it always returns the current UTC time.
🌐
W3Schools
w3schools.com › python › ref_module_time.asp
Python time Module
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... import time start = time.time() print(f'Start time: {start}') time.sleep(1) end = time.time() print(f'Elapsed: {end - start:.2f} seconds') Try it Yourself »
🌐
Programiz
programiz.com › python-programming › time
Python time Module (with Examples)
In Python, the time() function returns the number of seconds passed since epoch (the point where time begins).
🌐
Python documentation
docs.python.org › 3 › library › datetime.html
datetime — Basic date and time types
>>> import datetime as dt >>> delta = dt.timedelta( ... days=50, ... seconds=27, ... microseconds=10, ... milliseconds=29000, ... minutes=5, ... hours=8, ... weeks=2 ... ) >>> # Only days, seconds, and microseconds remain >>> delta datetime.timedelta(days=64, seconds=29156, microseconds=10) ... import datetime as dt instead of import datetime or from datetime import datetime to avoid confusion between the module and the class. See How I Import Python’s datetime Module.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-time-module
Python Time Module - GeeksforGeeks
July 23, 2025 - In this article, we will discuss the time module and various functions provided by this module with the help of good examples. As the name suggests Python time module allows to work with time in Python. It allows functionality like getting the ...
🌐
freeCodeCamp
freecodecamp.org › news › python-get-current-time
Python Get Current Time
July 13, 2022 - With the datetime and time modules of Python, you can get the current date and time, or the date and time in a particular time zone.
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › python › python_date_time.htm
Python - Date and Time
An object of date class is nave, whereas time and datetime objects are aware. A date object represents a date with year, month, and day. The current Gregorian calendar is indefinitely extended in both directions. ... If the value of any argument outside those ranges is given, ValueError is raised. from datetime import date date1 = date(2023, 4, 19) print("Date:", date1) date2 = date(2023, 4, 31) ... Date: 2023-04-19 Traceback (most recent call last): File "C:\Python311\hello.py", line 8, in <module> date2 = date(2023, 4, 31) ValueError: day is out of range for month
🌐
Real Python
realpython.com › ref › stdlib › time
time | Python Standard Library – Real Python
It allows you to work with time in a variety of ways, including getting the current time, measuring execution durations, and working with time in seconds since the epoch (January 1, 1970, 00:00:00 UTC).
Top answer
1 of 16
2636

Use time.time() to measure the elapsed wall-clock time between two points:

import time

start = time.time()
print("hello")
end = time.time()
print(end - start)

This gives the execution time in seconds.


Another option since Python 3.3 might be to use perf_counter or process_time, depending on your requirements. Before 3.3 it was recommended to use time.clock (thanks Amber). However, it is currently deprecated:

On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of “processor time”, depends on that of the C function of the same name.

On Windows, this function returns wall-clock seconds elapsed since the first call to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter(). The resolution is typically better than one microsecond.

Deprecated since version 3.3: The behaviour of this function depends on the platform: use perf_counter() or process_time() instead, depending on your requirements, to have a well defined behaviour.

2 of 16
1222

Use timeit.default_timer instead of timeit.timeit. The former provides the best clock available on your platform and version of Python automatically:

from timeit import default_timer as timer

start = timer()
# ...
end = timer()
print(end - start) # Time in seconds, e.g. 5.38091952400282

timeit.default_timer is assigned to time.time() or time.clock() depending on OS. On Python 3.3+ default_timer is time.perf_counter() on all platforms. See Python - time.clock() vs. time.time() - accuracy?

See also:

  • Optimizing code
  • How to optimize for speed
🌐
InfluxData
influxdata.com › home › python time module: a how-to guide | influxdata
Python Time Module: A How-To Guide | InfluxData
March 24, 2023 - You don’t have to install it ... as os). The time module provides a range of functions that allow users to perform tasks such as formatting strings, calculating durations, dealing with time zones, and more....
🌐
W3Schools
w3schools.com › python › python_datetime.asp
Python Datetime
The datetime() class also takes parameters for time and timezone (hour, minute, second, microsecond, tzone), but they are optional, and has a default value of 0, (None for timezone).
🌐
Built In
builtin.com › articles › timing-functions-python
Timing Functions in Python: A Guide | Built In
We’ve covered four of the most common methods in this guide: using the time module, the timeit module and profiling tools. Now, it’s your turn to put this knowledge into practice. Try timing some Python functions using the different methods we’ve discussed, and see how they compare.
🌐
Sentry
sentry.io › sentry answers › python › get the current time in python
Get the current time in Python | Sentry
import time print(time.time()) # will print the current Unix time as a floating point number ... Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski. SEE EPISODES ... David Y. — March 15, 2023 ... David Y. — January 30, 2023 ... James W. — October 21, 2022 · Fastest way to check if a list contains an item in Python
🌐
GeeksforGeeks
geeksforgeeks.org › python › get-current-date-and-time-using-python
How to Get Current Date and Time using Python - GeeksforGeeks
October 25, 2025 - Using the datetime module, you can fetch local time, UTC, or time in specific time zones, and format it as needed.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-time-time-method
Python | time.time() method - GeeksforGeeks
August 28, 2019 - epoch is: Thu Jan 1 00:00:00 1970 Time in seconds since the epoch: 1566454995.8361387 Code #2: Calculate seconds between two date ... # Python program to explain time.time() method # importing time module import time # Date 1 date1 = "1 Jan 2000 00:00:00" # Date 2 # Current date date2 = "22 Aug 2019 00:00:00" # Parse the date strings # and convert it in # time.struct_time object using # time.strptime() method obj1 = time.strptime(date1, "% d % b % Y % H:% M:% S") obj2 = time.strptime(date2, "% d % b % Y % H:% M:% S") # Get the time in seconds # since the epoch # for both time.struct_time objects time1 = time.mktime(obj1) time2 = time.mktime(obj2) print("Date 1:", time.asctime(obj1)) print("Date 2:", time.asctime(obj2)) # Seconds between Date 1 and date 2 seconds = time2 - time1 print("Seconds between date 1 and date 2 is % f seconds" % seconds)
🌐
iO Flood
ioflood.com › blog › python-time
Python Time Module: Comprehensive Guide
February 7, 2024 - In this example, we measure the execution time of two functions and compare them. This way, you can determine which function is more efficient. Python’s time module represents time in tuples as well. These tuples are handy when you want to display time in a more human-readable format or when you want to extract specific details like year, month, day, hour, minute, etc.