Have you ever seen an API return "created_at": 1745913600? That seemingly cryptic integer is a Unix timestamp — the standard format for representing time in software. Understanding why it exists and how to use it correctly is a fundamental skill for every developer.
1. What Is a Unix Timestamp?
A Unix timestamp is the number of seconds elapsed since January 1, 1970, 00:00:00 UTC (called the Unix Epoch). For example, 1745913600 represents April 29, 2026, 00:00:00 UTC.
Programs use this integer instead of human-readable strings for three key reasons:
- Timezone-neutral:
1745913600refers to the same absolute moment on every system worldwide — no ambiguity about "Tokyo time" vs "New York time" - Easy to compute: Calculating time differences or sorting events is just integer arithmetic
- Universal format: Every language and database can parse the same integer without ambiguity
2. Seconds vs. Milliseconds: The Most Common Confusion
Unix timestamps are defined in seconds, but modern systems — especially JavaScript and many APIs — use milliseconds, adding three digits:
| Format | Example | Notes |
|---|---|---|
| Seconds | 1745913600 |
10 digits — Unix standard, used by C/Python/PHP |
| Milliseconds | 1745913600000 |
13 digits — JavaScript's Date.now() returns this |
| Microseconds | 1745913600000000 |
16 digits — used by some databases and high-precision systems |
Quick identification: count the digits. 10 digits → seconds; 13 digits → milliseconds. Treating a millisecond timestamp as seconds will give you a date in the year 58,000 — one of the most common beginner bugs.
3. API Design: Time Field Best Practices
| Format | Example | Pros | Cons |
|---|---|---|---|
| Unix timestamp (seconds) | 1745913600 |
Fast computation, no timezone ambiguity, compact | Not human-readable |
| ISO 8601 string | 2026-04-29T00:00:00Z |
Human-readable, includes timezone info (Z = UTC) | String parsing varies by language |
Industry Recommendations
- Internal APIs: Use integer timestamps to avoid timezone misinterpretation
- Public-facing APIs: Use ISO 8601 (
2026-04-29T00:00:00Z) for developer readability - Always use UTC: Store and transmit in UTC; convert to the user's timezone only at display time
4. Database Storage: INT, DATETIME, or TIMESTAMP?
| Type | Example | Best For | Caveats |
|---|---|---|---|
BIGINT |
1745913600 |
High-performance queries, cross-database portability | Use BIGINT (not INT) to avoid the 2038 problem |
DATETIME |
2026-04-29 00:00:00 |
Human-readable storage, timezone-independent | MySQL DATETIME has no timezone info — application must enforce UTC |
TIMESTAMP |
2026-04-29 00:00:00 |
Auto timezone conversion in MySQL | Limited to 2038 in 32-bit systems; MySQL 8 partially mitigates this |
The Year 2038 Problem: A 32-bit signed integer maxes out at 2147483647, which corresponds to January 19, 2038 03:14:07 UTC. After that, it overflows to zero. The fix: use 64-bit integers (BIGINT), which safely covers billions of years.
5. Cross-Language Timestamp Reference
JavaScript
const ms = Date.now(); // milliseconds: 1745913600000 const sec = Math.floor(Date.now() / 1000); // seconds: 1745913600 const date = new Date(1745913600 * 1000); // timestamp → Date const ts = Math.floor(date.getTime() / 1000); // Date → timestamp (seconds)
Python
import time, datetime, timezone ts = time.time() # current seconds (float) dt = datetime.datetime.fromtimestamp(1745913600, tz=timezone.utc) ts = dt.timestamp() # datetime → seconds
PHP
$ts = time(); // current seconds
echo date('Y-m-d H:i:s', $ts);
$ts = strtotime('2026-04-29 00:00:00 UTC');
Go
ts := time.Now().Unix() // seconds ms := time.Now().UnixMilli() // milliseconds t := time.Unix(1745913600, 0).UTC() // timestamp → Time
6. Common Mistakes
| Mistake | Symptom | Fix |
|---|---|---|
| Treating milliseconds as seconds | Dates show up in the year 58,000 | Divide by 1000 or confirm the field unit |
| Storing local time as UTC | Times are off by your UTC offset (e.g., 8 hours) | Always store in UTC, convert at display time |
| Using 32-bit INT for timestamps | Overflow on Jan 19, 2038 | Use BIGINT (64-bit) |
| Timezone-unspecified strings | Different servers interpret differently | Always append Z or offset (e.g., +08:00) to ISO 8601 |
Summary
- A Unix timestamp is seconds elapsed since 1970-01-01 00:00:00 UTC — timezone-independent
- 10 digits = seconds; 13 digits = milliseconds — confusing the two is one of the most common bugs
- API design: integers for internal APIs, ISO 8601 for public APIs, always UTC
- Database: use BIGINT for timestamp storage to avoid the Year 2038 Problem
- All major languages have standard library functions for timestamp conversion — no manual math needed