Python Glossary Русский

all Python 3timefunction

time.time()

clocks and timing

The current time in seconds since the Unix epoch (1 January 1970 UTC) as a float — a timestamp to store in a log, a file or a database.

Syntax

time.time() -> float

This is the wall clock: NTP or the user can adjust it, so the difference of two calls can be negative or jump by an hour — measure intervals with monotonic() or perf_counter(). The number does not depend on the time zone: it is the same in Moscow and London, the zone only appears in localtime(). A common import mix-up: after from datetime import time the name time is the time-of-day class, and time.time() fails with AttributeError.

Examples

import time
print(time.time())  # → ? 1791331200.123456 — зависит от момента запуска
print(time.time() > 1.7e9)  # → True
from datetime import time
try:
    time.time()
except AttributeError as e:
    print(e)  # → type object 'datetime.time' has no attribute 'time'

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy