Timestamp Converter
Convert Unix timestamps to human-readable dates and vice versa. Support seconds and milliseconds.
// Get current Unix timestamp (seconds)const timestamp = Math.floor(Date.now() / 1000);// Get current timestamp (milliseconds)const timestampMs = Date.now();// Convert timestamp to Dateconst date = new Date(timestamp * 1000);// Convert Date to timestampconst ts = Math.floor(date.getTime() / 1000);
You May Also Like
What is a Unix Timestamp?
A Unix timestamp (also called Epoch time or POSIX time) is the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC - a moment known as the "Unix Epoch."
Right now, as you read this, the timestamp is a number like 1705312800.
Why January 1, 1970? When Unix was being developed in the early 1970s, the creators needed a starting point. They picked a recent, round date. The first Unix systems couldn't count very far back anyway!
Why does this matter to you?
- Timestamps are language-agnostic - every programming language understands them
- They're timezone-independent - always in UTC
- Easy to compare and calculate time differences
- Used everywhere: databases, APIs, log files, cookies
Timestamp Formats
| Format | Unit | Example | Common Usage |
|---|---|---|---|
| Unix (seconds) | Seconds | 1705312800 | Most APIs, databases |
| Unix (milliseconds) | Milliseconds | 1705312800000 | JavaScript, Java |
| Unix (microseconds) | Microseconds | 1705312800000000 | High-precision logs |
| Unix (nanoseconds) | Nanoseconds | 1705312800000000000 | Go, system calls |
Quick check: If the number is 10 digits, it's seconds. If it's 13 digits, it's milliseconds. JavaScript's Date.now() returns milliseconds!
Memorable Timestamps
๐ Unix Epoch Milestones
| Timestamp | Date | Event |
|---|---|---|
0 | Jan 1, 1970 | The beginning of Unix time |
1000000000 | Sep 9, 2001 | First 10-digit timestamp |
1234567890 | Feb 13, 2009 | "Epoch party" celebrated worldwide |
1500000000 | Jul 14, 2017 | 1.5 billion seconds |
2000000000 | May 18, 2033 | The next big milestone |
2147483647 | Jan 19, 2038 | โ ๏ธ Y2K38 Problem |
โ ๏ธ The Year 2038 Problem (Y2K38)
Many older systems store timestamps as a signed 32-bit integer, which maxes out at 2147483647 (January 19, 2038, 03:14:07 UTC).
After this moment, these systems will "overflow" and think it's December 13, 1901!
Most modern systems use 64-bit integers, which won't overflow for 292 billion years.
Timestamps and Timezones
The Beauty of UTC
Unix timestamps are always in UTC (Coordinated Universal Time). This solves the timezone headache:
Timestamp: 1705312800
= Jan 15, 2024 10:00:00 UTC
= Jan 15, 2024 05:00:00 EST (New York)
= Jan 15, 2024 19:00:00 JST (Tokyo)
= Jan 15, 2024 11:00:00 CET (Berlin)
Same number, different local times. When working with timestamps:
- Store everything as UTC timestamps
- Convert to local time only for display
- Accept user input in their timezone, convert to UTC immediately
Common mistake: Assuming a timestamp is in your local timezone. It's not - it's always UTC!
Practical Conversion Tips
Quick Mental Math
- 1 day = 86,400 seconds
- 1 week = 604,800 seconds
- 1 month โ 2,592,000 seconds (30 days)
- 1 year โ 31,536,000 seconds
Common Operations:
// Current timestamp
Math.floor(Date.now() / 1000)
// Add 1 day
timestamp + 86400
// Subtract 1 week
timestamp - 604800
// Start of today (UTC)
Math.floor(Date.now() / 86400000) * 86400
Debugging Timestamps:
When you see a suspicious timestamp:
- Check the digit count (10 = seconds, 13 = milliseconds)
- Use a converter to verify the date makes sense
- Check if it's negative (before 1970) or in the future
Timestamps in APIs
Common API Patterns:
// Twitter/X style (seconds)
{
"created_at": 1705312800
}
// JavaScript style (milliseconds)
{
"timestamp": 1705312800000
}
// ISO 8601 string (human-readable)
{
"created_at": "2024-01-15T10:00:00Z"
}
Best Practices:
- Always document whether you use seconds or milliseconds
- Include timezone info or state "all times are UTC"
- Use ISO 8601 strings for human-facing APIs
- Use numeric timestamps for machine-to-machine communication
Fun Timestamp Facts
๐ Negative Timestamps Dates before 1970 are represented as negative numbers:
-1= December 31, 1969, 23:59:59 UTC-86400= December 31, 1969, 00:00:00 UTC
๐ Your Birthday in Unix Time
Born on March 15, 1990? Your timestamp is approximately 637,632,000!
โฐ New Year's Eve 1999
The Y2K bug was famously a non-event, but Unix systems weren't affected anyway - their "2000" was just another second tick to 946684800.
๐ Leap Seconds Unix timestamps pretend leap seconds don't exist. When a leap second occurs, the timestamp repeats! This keeps timestamps predictable but slightly inaccurate astronomically.