Skip to main content
Ordinary Utils Fast, free tools that respect your time.

Unix Timestamps: Understanding Time in Computing

How computers measure and represent time.

Development 10 min read Last updated: June 19, 2026

What is a Unix Timestamp?

A Unix timestamp (also called Epoch time, POSIX time, or Unix time) is a way of tracking time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at 00:00:00 UTC.

For example, the timestamp 1609459200 represents January 1st, 2021 at midnight UTC. Every second that passes increments this number by one.

Current Unix Timestamp
1781839898

Why Use Unix Timestamps?

Unix timestamps offer several advantages over human-readable date formats:

  • Time zone independence: Timestamps are always in UTC. No confusion about which time zone a date refers to.
  • Easy math: Calculating time differences is simple subtraction. Add 86400 to move forward one day.
  • Compact storage: A 32-bit integer (4 bytes) stores a complete date and time.
  • Sorting: Timestamps sort naturally as numbers.
  • Language agnostic: Every programming language can work with integers.

The Unix Epoch

The Unix Epoch (January 1, 1970, 00:00:00 UTC) was chosen for practical reasons when Unix was being developed at Bell Labs in the early 1970s:

  • It was a recent, round date at the time of Unix's creation
  • Starting from a fixed point simplified time calculations
  • Using seconds as the unit provided sufficient precision for most applications

Dates before the epoch are represented as negative numbers. For example, -86400 represents December 31, 1969.

Timestamp Precision

Different systems use different precision levels:

Seconds (10 digits)
1609459200

Standard Unix timestamp. Used by most systems.

Milliseconds (13 digits)
1609459200000

JavaScript's Date.now(). Common in web applications.

Microseconds (16 digits)
1609459200000000

Used when high precision is needed (databases, logging).

Nanoseconds (19 digits)
1609459200000000000

High-precision timing, scientific applications.

The Year 2038 Problem (Y2K38)

Many systems store Unix timestamps as 32-bit signed integers. The maximum value is 2,147,483,647, which corresponds to:

January 19, 2038, 03:14:07 UTC

After this moment, 32-bit timestamps will overflow and wrap to negative numbers, potentially causing systems to interpret dates as December 1901.

Solutions include:

  • 64-bit timestamps: Modern systems use 64-bit integers, good for billions of years.
  • Database migrations: Update timestamp columns to BIGINT or native datetime types.
  • Code audits: Identify and update code using 32-bit time functions.

Working with Time Zones

Unix timestamps are always in UTC, but applications often need to display local times:

// JavaScript
const timestamp = 1609459200;
const date = new Date(timestamp * 1000);

// Display in user's local time zone
date.toLocaleString(); // Varies by user's settings

// Display in specific time zone
date.toLocaleString('en-US', { timeZone: 'America/New_York' });
// "12/31/2020, 7:00:00 PM"

Best Practices

  • Store in UTC: Always store timestamps in UTC in your database.
  • Convert on display: Convert to local time only when showing to users.
  • Use time zone libraries: Libraries like Moment.js, Luxon, or date-fns handle edge cases.
  • Be aware of DST: Daylight saving time can cause unexpected behavior.

Common Time Calculations

// Useful constants (in seconds)
const MINUTE = 60;
const HOUR = 3600;
const DAY = 86400;
const WEEK = 604800;

// Get current timestamp
const now = Math.floor(Date.now() / 1000);

// Add one day
const tomorrow = now + DAY;

// Calculate difference
const diff = timestamp2 - timestamp1;
const daysBetween = Math.floor(diff / DAY);

// Start of today (UTC)
const today = Math.floor(now / DAY) * DAY;

Timestamps in Different Languages

JavaScript

// Current timestamp (milliseconds)
Date.now();  // 1609459200000

// Current timestamp (seconds)
Math.floor(Date.now() / 1000);  // 1609459200

// Timestamp to Date
new Date(1609459200 * 1000);

// Date to timestamp
Math.floor(new Date('2021-01-01').getTime() / 1000);

Python

import time
from datetime import datetime

# Current timestamp
time.time()  # 1609459200.123456

# Timestamp to datetime
datetime.fromtimestamp(1609459200)  # Local time
datetime.utcfromtimestamp(1609459200)  # UTC

# Datetime to timestamp
datetime(2021, 1, 1).timestamp()

PHP

// Current timestamp
time();  // 1609459200

// Timestamp to formatted date
date('Y-m-d H:i:s', 1609459200);  // "2021-01-01 00:00:00"

// String to timestamp
strtotime('2021-01-01');  // 1609459200

// DateTime object
$dt = new DateTime('@1609459200');

SQL

-- MySQL
SELECT UNIX_TIMESTAMP();  -- Current timestamp
SELECT FROM_UNIXTIME(1609459200);  -- To datetime
SELECT UNIX_TIMESTAMP('2021-01-01');  -- String to timestamp

-- PostgreSQL
SELECT EXTRACT(EPOCH FROM NOW());
SELECT TO_TIMESTAMP(1609459200);

Common Pitfalls

  • Milliseconds vs seconds: JavaScript uses milliseconds; most other languages use seconds. Watch for 13-digit vs 10-digit timestamps.
  • Time zone assumptions: Never assume timestamps are in local time. Always treat them as UTC.
  • Leap seconds: Unix time doesn't account for leap seconds. For most applications, this doesn't matter.
  • 32-bit overflow: Test your systems with dates beyond 2038 to catch potential issues.
  • DST transitions: Be careful with arithmetic around daylight saving time changes.

Key Takeaways

  • Unix timestamps count seconds since January 1, 1970 UTC
  • They're time zone independent—always UTC
  • Simple math: differences, additions, comparisons are easy
  • Watch for 32-bit limitations (Y2K38 problem)
  • JavaScript uses milliseconds; most others use seconds
  • Always store in UTC, convert to local time for display only

Convert Timestamps

Use our timestamp converter to translate between Unix timestamps and human-readable dates.

Open Timestamp Converter →