What is a Unix Timestamp?
A Unix timestamp is the number of seconds (or milliseconds) elapsed since January 1, 1970 00:00:00 UTC. It is a simple integer: 1749812400. Every timezone sees the same number for the same moment — no ambiguity.
Direct Comparison
| Property | Unix Timestamp | ISO 8601 |
|---|---|---|
| Example | 1749812400 | 2026-06-13T10:30:00Z |
| Human readable | No | Yes |
| Timezone ambiguity | None | None (with Z) |
| Storage size | 4-8 bytes (int) | ~24 bytes (string) |
| Duration math | Subtract two integers | Requires Date parsing |
| Year 2038 problem | Only with 32-bit int | No limit |
When to Use Unix Timestamps
- Redis TTL values and integer-based expiry systems
- Mathematical calculations: duration = timestamp2 - timestamp1
- High-throughput databases where integer comparison beats string parsing
- Unix system calls and tools that natively use epoch time
When to Use ISO 8601
- Public APIs — human-readable, easy to inspect in logs
- Date-only values (2026-06-13) — Unix timestamps have no meaning without a time component
- User-facing data exports (CSV, JSON reports)
- PostgreSQL timestamptz columns (natively return ISO format)
JavaScript Conversion
// Unix seconds → Date
const d = new Date(1749812400 * 1000); // multiply by 1000 for ms
// Date → Unix seconds
const unix = Math.floor(Date.now() / 1000);
// Date → ISO 8601
new Date().toISOString(); // "2026-06-13T10:30:00.000Z"
// ISO 8601 → Unix seconds
Math.floor(new Date("2026-06-13T10:30:00Z").getTime() / 1000);
Recommendation
Use ISO 8601 in public APIs and logs — human-readable is worth the extra bytes. Use Unix timestamps internally for high-throughput date-time columns. Always store UTC, convert to local time only at the UI layer.