🌐
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 »
🌐
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).
🌐
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.
🌐
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.
🌐
InfluxData
influxdata.com › home › what is the time library in python? a helpful guide
What is the Time Library in Python? A Helpful Guide | InfluxData
October 20, 2023 - The time() function in Python returns the current time in seconds since the beginning of the epoch.
🌐
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 › 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).
🌐
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.
Find elsewhere
🌐
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 ...
🌐
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).
🌐
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
🌐
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.
🌐
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.
🌐
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.
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
🌐
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.
🌐
PyPI
pypi.org › project › TIME-python
TIME-python
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-time-time-method
Python | time.time() method - GeeksforGeeks
August 28, 2019 - This module comes under Python’s standard utility modules. time.time() method of Time module is used to get the time in seconds since epoch. The handling of leap seconds is platform dependent.