Unix Timestamps Explained: What They Are and How to Use Them
Unix timestamps appear in logs, APIs, and databases everywhere. Here's what they are, how to convert them, and common pitfalls to avoid.
Open a server log and you'll see numbers like 1740892800 everywhere. These are Unix timestamps — the count of seconds since January 1, 1970. Once you understand them, you can read any log, work with any API response that uses them, and avoid the common timezone bugs they help prevent.
Why Unix Timestamps Exist
A date like '3/15/26' is ambiguous — is that March 15 or the 15th day of the 3rd month in a 2-digit year? Is it in your timezone or the server's? Unix timestamps eliminate all of this: 1742054400 always means exactly the same moment for every computer on earth, regardless of timezone.
Converting Timestamps
Paste any Unix timestamp and see the human-readable date/time in any timezone. Or enter a date to see the Unix timestamp.
Millisecond vs Second Timestamps
JavaScript's Date.now() returns milliseconds since epoch (1740892800000 instead of 1740892800). Other languages (Python, Unix tools) use seconds. Divide JavaScript timestamps by 1000 to get seconds. Multiply seconds by 1000 to get milliseconds. Mixing these is a common source of bugs — a timestamp that's 1000× too large produces a date far in the future.
Getting the Current Timestamp
- JavaScript: Math.floor(Date.now() / 1000) for seconds, Date.now() for milliseconds
- Python: import time; int(time.time())
- Bash: date +%s
- SQL (PostgreSQL): EXTRACT(EPOCH FROM NOW())
- PHP: time()
Debugging timestamps
When debugging a Unix timestamp you're not sure about, check the magnitude: 10 digits = seconds (year 2001–2286), 13 digits = milliseconds (year 2001–2286 too). If you get a weird date from a conversion, you probably mixed up seconds and milliseconds.
Frequently Asked Questions
What is a Unix timestamp?+
What is the Year 2038 problem?+
How do I convert a Unix timestamp to a readable date?+
Should I store timestamps as Unix integers or ISO strings in my database?+
🔧 Free Tools Used in This Guide
FreeToolKit Team
FreeToolKit Team
We build free browser-based tools and write practical guides that skip the fluff.
Tags: