🌐
Python
docs.python.org › 3 › library › time.html
time — Time access and conversions
It returns a floating-point number, for compatibility with time(). If the input value cannot be represented as a valid time, either OverflowError or ValueError will be raised (which depends on whether the invalid value is caught by Python or the underlying C libraries).
🌐
W3Schools
w3schools.com › python › ref_module_time.asp
Python time Module
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems 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 »
🌐
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 ...
🌐
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 › 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.
🌐
MicroPython
docs.micropython.org › en › latest › library › time.html
time – time related functions — MicroPython latest documentation
The time module provides functions for getting the current time and date, measuring time intervals, and for delays.
🌐
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).
🌐
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
Find elsewhere
🌐
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.
Top answer
1 of 16
2637

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
🌐
W3Schools
w3schools.com › python › python_datetime.asp
Python Datetime
December 31, 2018 - 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).
🌐
Career Karma
careerkarma.com › blog › python › how to use the python time module
How to Use the Python Time Module: A Complete Guide | Career Karma
December 1, 2023 - The Python time module lets you work with time. On Career Karma, learn how to use the Python time module and its built-in functions.
🌐
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....
🌐
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.
🌐
IONOS
ionos.com › digital guide › websites › web development › python time module subtitle-h1: what is python’s time module?
What is Python’s time module? - IONOS
May 27, 2025 - The Python time module is essential for im­ple­ment­ing and handling time data in the pro­gram­ming language. With this module, it’s possible to display the current time, format dates and times, and specify a timeframe for running a function.
🌐
Real Python
realpython.com › python-get-current-time
How to Get and Use the Current Time in Python – Real Python
September 25, 2023 - In this tutorial, you'll be getting the current time in Python. You'll get your hands on a datetime object that represents the current time. You'll see how to format it according to international standards, and you'll even check out how computers represent time.
🌐
Sentry
sentry.io › sentry answers › python › get the current time in python
Get the current time in Python | Sentry
We can get the current time using the now method in Python’s built-in datetime library.