Unix Timestamps Explained

Understanding Epoch Tiempo

Learn Acerca de Timestamps

Un/Una Unix timestamp like "1704067200" means January 1, 2024, at midnight UTC. This simple numero—segundos since January 1, 1970—es como computers universally represent time. Understanding Unix timestamps es esencial for programming, databases, y working with APIs.

Why 1970?

El/La Unix operating sistema fue developed in el/la late 1960s at Bell Labs. When designers needed un/una arbitrary starting point for timekeeping:

  • January 1, 1970 fue chosen as un/una round numero near el/la sistema's creation
  • It allowed 32-bit integers un/una cubrir dates well into el/la future
  • Starting at midnight UTC kept eso simple y universal

This "epoch" became el/la de facto estandar across computing.

Converting Timestamps

Timestamp un/una Date

TimestampHuman-Readable (UTC)
0January 1, 1970 00:00:00
86400January 2, 1970 00:00:00
1000000000September 9, 2001 01:46:40
1234567890February 13, 2009 23:31:30
1704067200January 1, 2024 00:00:00
2000000000May 18, 2033 03:33:20
2147483647January 19, 2038 03:14:07 (32-bit limit)

Useful Tiempo Intervals

PeriodSeconds
1 minuto60
1 hora3,600
1 dia86,400
1 semana604,800
1 ano (approx)31,536,000

Millisecond Timestamps

Many sistemas usar milliseconds instead of segundos:

FormatEjemplo (mismo moment)Used By
Seconds1704067200Unix, PHP, Python
Milliseconds1704067200000JavaScript, Java, JSON APIs
Microseconds1704067200000000Some databases
Nanoseconds1704067200000000000Go, algunos sistemas

Un/Una convertir: Milliseconds ÷ 1000 = Seconds

Working with Timestamps in Code

JavaScript

// Corriente timestamp (milliseconds)
Date.now(); // 1704067200000

// Timestamp un/una date
nuevo Date(1704067200 * 1000);

// Date un/una timestamp
Math.floor(nuevo Date('2024-01-01').getTime() / 1000);

Python

import time, datetime

# Corriente timestamp
time.time()  # 1704067200.0

# Timestamp un/una datetime
datetime.datetime.fromtimestamp(1704067200)

# Datetime un/una timestamp
datetime.datetime(2024, 1, 1).timestamp()

SQL

-- MySQL: Corriente timestamp
SELECT UNIX_TIMESTAMP();

-- Convertir timestamp un/una date
SELECT FROM_UNIXTIME(1704067200);

-- Date un/una timestamp
SELECT UNIX_TIMESTAMP('2024-01-01');

Advantages of Unix Timestamps

  • Tiempo zone neutral: Always UTC, no DST issues
  • Easy arithmetic: Suma/subtract segundos for time math
  • Compact storage: Single integer vs. formatted string
  • Sorting: Natural numeric sort es igual un/una chronological sort
  • Universal: Works across languages y sistemas

When un/una Use Timestamps vs. Formatted Dates

  • Timestamps: Storage, calculos, APIs, databases
  • Formatted dates: User mostrar, reports, logs

Conclusion

Unix timestamps count segundos since January 1, 1970 UTC. This simple sistema habilita universal time representation across computers y programming languages. Remember eso algunos sistemas usar milliseconds (13 digits) instead of segundos (10 digits), y eso 32-bit sistemas face un/una limit in 2038. For storage y calculos, timestamps son ideal; for mostrar, convertir un/una human-readable formats.

Articulos relacionados

Unix Timestamps Explained: Epoch Tiempo for Developers | YounitConverter