Convert Unix epoch timestamps to ISO datetimes and back, in any IANA timezone. The bundled script auto-detects whether an epoch value is in seconds, milliseconds, microseconds, or nanoseconds.
Run the script with one of three subcommands:
bash
# Current time (UTC by default)
python3 scripts/epoch.py now --tz Asia/Shanghai
# Epoch -> ISO datetime (unit auto-detected)
python3 scripts/epoch.py to-human 1718000000 --tz UTC
# Datetime -> epoch seconds
python3 scripts/epoch.py to-epoch "2024-06-10 08:00:00" --tz Asia/Shanghai
now [--tz TZ] — print current epoch seconds, epoch millis, and ISO datetime.to-human <EPOCH> [--tz TZ] — convert an epoch value to an ISO datetime. Unit is auto-detected by magnitude (s / ms / µs / ns).to-epoch "<DATETIME>" [--tz TZ] — convert a datetime string to epoch seconds. Accepts YYYY-MM-DD[ T]HH:MM[:SS] and YYYY-MM-DD.--tz accepts any IANA timezone name (e.g. UTC, Asia/Shanghai, America/New_York). Defaults to UTC.zoneinfo (Python 3.9+). On older runtimes, only UTC is available.--tz, not the machine's local time.