Introduction
Unix timestamps (also called epoch time) are the standard way computers represent time. You'll encounter them in APIs, databases, logs, and configuration files. Understanding timestamps helps you debug time-related issues, convert between formats, and work with time-based data across different systems.
What is a Unix Timestamp?
A Unix timestamp is the number of seconds that have elapsed since January 1, 1970 (the Unix epoch). This single integer represents any moment in time, making it ideal for storage and computation.
Key Facts
Why Use Timestamps?
- Universal FormatWorks across all programming languages and systems. No timezone confusion.
- Easy ArithmeticSubtract timestamps to get duration. Add seconds to shift time. Simple math.
- Compact StorageA single integer takes less space than formatted date strings.
Common Date/Time Formats
| Format | Example | Use Case |
|---|---|---|
| Unix Timestamp | 1704067200 | APIs, databases, logs |
| ISO 8601 | 2024-01-01T00:00:00Z | JSON APIs, web standard |
| Milliseconds | 1704067200000 | JavaScript, Java |
| RFC 2822 | Mon, 01 Jan 2024 00:00:00 GMT | Email headers |
| Custom | 2024-01-01 12:00 AM | User display |
Practical Use Cases
Debugging APIs
When an API returns timestamps, convert them to readable dates to verify expiration times, scheduling, and time-based logic.
Log Analysis
Server logs often use timestamps. Convert them to local time to understand when errors occurred and correlate events.
JWT Tokens
JWT expiration is stored as timestamps. Decode and check if tokens are still valid before processing requests.
Database Queries
Query data by time range using timestamps. Calculate age, duration, or filter records by date boundaries.
Quick Tips
- JavaScript uses milliseconds: multiply Unix timestamp by 1000
- Timestamps are always UTC - convert to local time for display
- 32-bit timestamps overflow in 2038 (use 64-bit for future-proofing)
- ISO 8601 with timezone: 2024-01-01T00:00:00-05:00
- Current timestamp: ~1.7 billion seconds since 1970