Convert between Unix epoch timestamps and human-readable datetimes, with timezone support and automatic unit detection (seconds/millis/micros/nanos). Use whe...
数据分析
datefmt-lite
试用Convert and format dates/times with zero external APIs — ISO 8601, Unix epoch, RFC 2822, and timezone conversion using only the local `date` binary and TZ database. Use when you need quick timestamp formatting, epoch conversion, duration arithmetic, or "what time is it in <city>" math without network calls.
它能做什么
Convert and format dates/times with zero external APIs — ISO 8601, Unix epoch, RFC 2822, and timezone conversion using only the local `date` binary and TZ database. Use when you need quick timestamp formatting, epoch conversion, duration arithmetic, or "what time is it in <city>" math without network calls.
技能文档
datefmt-lite
Small, dependency-free toolkit for turning one timestamp format into another.
Everything runs locally through GNU coreutils date and the TZ database
(/usr/share/zoneinfo). No curl, no API keys, no network.
When to use
- Convert between ISO 8601 ↔ Unix epoch ↔ RFC 2822
- "What time is 2026-09-06 08:28 GMT+8 in UTC / Los Angeles?"
- Add or subtract durations from a date
- Sanity-check cron expressions against real weekdays
- Any shell environment where installing a library is overkill
Prerequisites
- GNU coreutils
date(Linux default; macOS:brew install coreutils, usegdateor prefix commands withg). - TZ database present (
ls /usr/share/zoneinfoshould list regions).
Core recipes
1. Now in common formats
date +%s # Unix epoch seconds (handy for logs)
date -u +"%Y-%m-%dT%H:%M:%SZ" # ISO 8601 UTC (sortable, unambiguous)
date -R # RFC 2822 (email/HTTP headers)
2. Parse "ISO string → epoch"
date -u -d "2026-09-06T08:28:00+08:00" +%s # → 1788654480 (GNU date)
# Reading an epoch back into a human form:
date -u -d "@1788654480" # → Sun Sep 6 00:28:00 UTC 2026
3. Timezone conversion without computing offsets yourself
Pick any zone name from timedatectl list-timezones or /usr/share/zoneinfo.
# "2026-09-06 08:28 GMT+8" expressed in three other zones:
TZ=America/Los_Angeles date -d "2026-09-06 08:28 +0800"
# Sat Sep 5 17:28:00 PDT 2026
TZ=Europe/Berlin date -d "2026-09-06 08:28 +0800"
TZ=Australia/Sydney date -d "2026-09-06 08:28 +0800"
The trick: TZ=... date re-renders the same instant in the target zone,
so you never add/subtract offsets by hand (DST handled automatically).
4. Duration arithmetic
date -d "2026-09-06 + 45 days" +%F # add 45 days → 2026-10-21
date -d "2026-09-06 08:28 - 3 hours" +%s # subtract 3h → epoch
echo $(( $(date -d "2026-10-01" +%s) - $(date -d "2026-09-06" +%s) ))
# seconds between two dates (divide by 86400 for days)
5. Cron-expression sanity check
Before scheduling 30 2 * * 1-5, confirm the weekday names for the run dates:
for d in 2026-09-07 2026-09-08 2026-09-12; do
echo "$d -> $(date -d "$d" +%A) $([ "$(date -d "$d" +%u)" -le 5 ] && echo weekday || echo Weekend)"
done
Common mistakes to avoid
- Writing
TZ=Asia/Shanghai dateinstead of converting a moment. That renders now, not a timestamp you were holding. Usedate -d "". - Forgetting
-uwhen logging. Local-zone strings in logs sort wrong across DST boundaries and confuse anyone not in your zone. - Relying on
%Falone — always include zone or epoch when persisting.
Verification one-liner
Round-trip check that your toolchain parses what it emits:
e=$(date +%s); iso=$(date -u -d "@$e" +"%Y-%m-%dT%H:%M:%SZ"); \
back=$(date -u -d "$iso" +%s); [ "$e" = "$back" ] && echo "OK"
If this prints OK, your date build handles ISO 8601 correctly.
相关技能
Convert any time representation — unix timestamps (s/ms/us/ns), ISO 8601/RFC 3339/RFC 2822, strftime, spreadsheet serials, IANA timezones, natural language ("3 days ago"/"下周一"), date arithmetic, durations. Use for bare epoch numbers, timezone/format conversion, 时间戳转北京时间, or a whole time column.
Convert time between different timezones using IANA timezone database. Supports 12/24-hour formats, specific dates, and automatic DST handling.
Print the current UTC time and ISO date in a deterministic, copy-friendly format. Use when an agent or operator needs a stable timestamp string for logs, file names, notes, or manifests and wants a single reusable command instead of rewriting date formatting each time.
Web Data Convertor: Convert between web formats: JSON↔CSV, JSON↔XML, JSON↔YAML, Markdown↔HTML, query strings, Unix timestamps↔dates with timezone support. Us...
Use for Nager.Date Community API v4 public-holiday integration, country or holiday lookups, commercial-use eligibility checks, and direct read-only SDK or CLI workflows.