Tool
Python Unix Timestamp Snippets
Python examples for current Unix time, timestamp-to-datetime conversion, UTC handling, milliseconds, and formatted date output using the standard library.
Python timestamp basics
Python's time.time() returns seconds since the Unix epoch as a floating-point number. Wrap it with int() for whole Unix seconds, or multiply by 1000 when you need milliseconds.
Timezone-aware datetime output
Use datetime.fromtimestamp(ts, tz=datetime.timezone.utc) for explicit UTC output. Avoid relying on the server's local timezone when generating values for logs, APIs, or database rows.