ID EN
Datetime

timestamp

Python 3.11

Return POSIX timestamp corresponding to the datetime instance. The return value is a float similar to that returned by time.time().

Syntax

PYTHON
datetime.timestamp()

Examples

Example 1
PYTHON
(dt - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds()
Example 2
PYTHON
timestamp = dt.replace(tzinfo=timezone.utc).timestamp()
Example 3
PYTHON
timestamp = (dt - datetime(1970, 1, 1)) / timedelta(seconds=1)

See Also

datetime float time.time() datetime datetime OverflowError datetime timestamp()