How to Convert Unix Timestamp to Date
If you ever query a database or API and get a response like 1711108800 instead of a date, you've just encountered a Unix Timestamp.
🕰️ What is Unix Time?
Unix time (also known as Epoch time) is a system for describing a point in time. It is the number of seconds that have elapsed since January 1, 1970 (Midnight UTC/GMT), not counting leap seconds.
Why do computers use this? Because dealing with timezones, leap years, days of the week, and daylight saving time is incredibly complex. A single integer counting seconds is unambiguous and extremely easy to store and compare in databases.
🧮 Seconds vs Milliseconds
One of the most common pitfalls when dealing with timestamps is confusing seconds with milliseconds.
- Seconds (10 digits): Standard Unix time (e.g.,
1711108800). Used heavily by backend systems and APIs (like Stripe). - Milliseconds (13 digits): Used heavily by Javascript (e.g.,
1711108800000).
[!TIP] If your date is rendering somewhere in the year 1970 instead of today, you probably passed a 10-digit second timestamp into a Javascript
Dateobject without multiplying it by 1000 first!
💻 Converting in Code
Here is how you convert a standard Unix timestamp to a Javascript Date object:
const unixTimestamp = 1711108800;
// Multiply by 1000 to convert seconds to milliseconds!
const date = new Date(unixTimestamp * 1000);
console.log(date.toLocaleString());
Need to quickly convert a timestamp right now without opening your terminal? Use our converter below!