Understanding Unix Timestamps: A Complete Guide for Developers

2026-05-20 · Development

What Is a Unix Timestamp?

A Unix timestamp is a way of tracking time as a running total of seconds. It counts the number of seconds that have elapsed since January 1, 1970 at 00:00:00 UTC — a reference point known as the "Unix Epoch."

For example, the Unix timestamp 1719000000 represents a specific moment in time: June 22, 2024 at approximately 00:00 UTC. Every second, this number increases by one.

Why Use Unix Timestamps?

Unix timestamps are ubiquitous in software development for several reasons:

  • Timezone independence: A timestamp represents the same instant worldwide. There is no ambiguity about whether it's in EST, PST, or JST — it's always UTC-based.
  • Easy comparison: Comparing two timestamps is a simple number comparison. If timestamp A is greater than timestamp B, event A happened after event B.
  • Efficient storage: Storing a 10-digit integer is far more space-efficient than storing a formatted date string like "2024-06-22T00:00:00Z".
  • Math operations: Adding 86,400 seconds to a timestamp gives you exactly 24 hours later. No need to worry about month boundaries or leap years.

Seconds vs. Milliseconds

Unix timestamps come in two common formats:

  • Seconds (10 digits): The original Unix timestamp format. Example: 1719000000
  • Milliseconds (13 digits): Used by JavaScript and many modern APIs for higher precision. Example: 1719000000000

A common source of bugs is mixing these two formats. If you pass a millisecond timestamp to a function expecting seconds, the date will be wildly incorrect (roughly 50,000 years in the future).

Working with Timestamps in Different Languages

JavaScript

const now = Date.now(); // milliseconds
const seconds = Math.floor(Date.now() / 1000);
const date = new Date(seconds * 1000);

Python

import time
seconds = int(time.time())
from datetime import datetime
dt = datetime.fromtimestamp(seconds)

PHP

$timestamp = time(); // seconds
$date = date('Y-m-d H:i:s', $timestamp);

MySQL

SELECT UNIX_TIMESTAMP(); -- current timestamp
SELECT FROM_UNIXTIME(1719000000); -- convert to date

Common Pitfalls

  • The Year 2038 problem: 32-bit signed integers will overflow on January 19, 2038. Systems using 32-bit timestamps will need to migrate to 64-bit integers.
  • Leap seconds: Unix timestamps do not account for leap seconds. Most systems simply ignore them, which can cause slight discrepancies with atomic time.
  • Timezone display: Always remember that a Unix timestamp is in UTC. Displaying it to users requires conversion to their local timezone.

TryQuickToolBox Timestamp Converter

Our free tool converts between Unix timestamps (seconds and milliseconds), ISO 8601 dates, UTC times, and local times. Auto-detection means you can paste any format and get instant results. Click any result to copy it to your clipboard.

Convert Timestamps Now →