A Unix timestamp is just a big number that tells a computer a date and time. It counts seconds from January 1, 1970 at 00:00:00 UTC, also called the Unix epoch [source: Wikipedia]. So if you see 1700000000, you are not looking at a password from a sleepy robot. You are looking at a date.
TLDR: Unix time is time written as seconds since January 1, 1970, in UTC. For example, 1700000000 means November 14, 2023, 22:13:20 UTC. A data team checking 50,000 server events can sort them faster with Unix timestamps because numbers are easier to compare than date strings. If a timestamp has 13 digits, it is probably in milliseconds, not seconds.
Table of Contents
Why Unix Time Exists
Computers love numbers. Dates are messy. Humans say “next Friday,” “11 PM,” or “five minutes ago.” Computers prefer something plain, like 1717243200.
That is the charm of Unix time. It turns time into one growing number. Every second, the number goes up by one. Simple. Brutal. Useful.
The starting point is called the Unix epoch. That is midnight on January 1, 1970, in UTC. UTC is the time standard used across servers, apps, databases, and logs.
Honestly, it feels like dates were invented to annoy developers. Time zones, daylight saving time, local formats, and weird calendars all pile on. Unix time skips much of that pain by starting with UTC and using plain seconds.
How to Read a Unix Timestamp
Let’s say you find this value:
1704067200
That number means:
- UTC time: January 1, 2024, 00:00:00
- New York: December 31, 2023, 19:00:00
- London: January 1, 2024, 00:00:00
- Tokyo: January 1, 2024, 09:00:00
Same timestamp. Different local times. That is why time zones matter when you show the date to a user.
Unix time itself does not store “New York time” or “Tokyo time.” It stores a moment. Your app then formats that moment for the person reading it.
Seconds vs Milliseconds
This is where people get burned.
A Unix timestamp can appear in seconds or milliseconds. Both are common. Both look similar at first. One tiny mistake can send your date far into the future or deep into the past.
- 10 digits: Usually seconds, like
1700000000 - 13 digits: Usually milliseconds, like
1700000000000
If your converted date says the year is 55840, do not panic. You probably treated milliseconds as seconds. Divide by 1000.
If your date lands in 1970 and should be recent, you may have treated seconds as milliseconds. Multiply by 1000.
How to Convert Unix Time by Hand
You usually do not convert Unix time by hand. Life is short. Still, the idea is easy.
- Start at January 1, 1970, 00:00:00 UTC.
- Add the number of seconds in the timestamp.
- Format the result as a date and time.
For example:
86400 means one day after the epoch.
Why? Because one day has:
- 24 hours
- 60 minutes per hour
- 60 seconds per minute
So:
24 × 60 × 60 = 86400
That makes 86400 equal to January 2, 1970, 00:00:00 UTC.
How to Convert Unix Time in Code
Most languages can convert Unix time with one or two lines. Thank goodness.
JavaScript
JavaScript dates use milliseconds. This trips people all the time.
const timestamp = 1700000000;
const date = new Date(timestamp * 1000);
console.log(date.toUTCString());
Why multiply by 1000? Because the timestamp is in seconds, but JavaScript wants milliseconds.
Python
from datetime import datetime, timezone
timestamp = 1700000000
date = datetime.fromtimestamp(timestamp, timezone.utc)
print(date)
This prints the date in UTC. That is usually what you want for logs, reports, and backend work.
PHP
$timestamp = 1700000000;
echo gmdate("Y-m-d H:i:s", $timestamp);
gmdate uses UTC. Regular date uses the server’s local time zone. That difference can cost you 30 minutes of head scratching.
How to Convert a Date to Unix Time
Sometimes you need to go the other way. You have a normal date. You want the timestamp.
Example:
January 1, 2024, 00:00:00 UTC becomes 1704067200.
In JavaScript:
const date = new Date("2024-01-01T00:00:00Z");
const timestamp = Math.floor(date.getTime() / 1000);
console.log(timestamp);
The Z means UTC. Do not skip it unless you mean local time. That missing letter can shift your result by hours.
In Python:
from datetime import datetime, timezone
date = datetime(2024, 1, 1, 0, 0, 0, tzinfo=timezone.utc)
timestamp = int(date.timestamp())
print(timestamp)
Where You See Unix Timestamps
Unix timestamps hide all over the place. You may see them in:
- Server logs, where every event needs a clean time marker.
- Databases, where sorting by number is fast.
- APIs, especially for events, payments, and messages.
- Analytics tools, where millions of actions need order.
- File systems, where created and modified times are stored.
Picture a shop app with 120,000 daily orders. Each order gets a timestamp. The app can sort purchases, build charts, detect delays, and spot spikes. Numbers make that work quick.
Common Mistakes
Unix time is simple. The tools around it are not always kind.
- Mixing seconds and milliseconds: The classic disaster.
- Forgetting UTC: Your timestamp is UTC, but your screen may show local time.
- Ignoring daylight saving time: Local display can jump by one hour.
- Using vague date strings:
01/02/2024can mean January 2 or February 1. - Storing local time only: This gets ugly when users live in many countries.
The cleaner plan is this:
- Store time in UTC.
- Use Unix timestamps or proper date types.
- Convert to local time only when showing it to users.
A Tiny Cheat Sheet
0= January 1, 1970, 00:00:00 UTC60= one minute after the epoch3600= one hour after the epoch86400= one day after the epoch1704067200= January 1, 2024, 00:00:00 UTC
Final Tip
If a timestamp looks strange, count the digits first. Ten digits usually means seconds. Thirteen digits usually means milliseconds. Then check the time zone. Those two checks fix most Unix time problems fast.
Unix timestamps may look cold and robotic. But they are just dates wearing number costumes. Once you know the trick, they are easy to read, convert, sort, and store.
