IMTools

Developer Tools

Timestamp Converter: Convert Unix Time and Epoch Timestamps

Free online timestamp converter. Convert between Unix timestamps, human-readable dates, and various time formats instantly.

IMTools TeamJan 4, 20255 min read

Timestamp Converter: Complete Guide

Timestamps are fundamental to software development, data analysis, and system administration. This guide covers everything you need to know about converting and using timestamps.

What is a Unix Timestamp?

A Unix timestamp (also called Epoch time or POSIX time) is the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC (the Unix Epoch).

Example

1735689600 = January 1, 2025, 00:00:00 UTC

Why Use Timestamps?

Advantages

  1. Universal: Same value worldwide, timezone-independent
  2. Simple: Just a single integer number
  3. Easy to Compare: Direct numerical comparison
  4. Efficient Storage: Compact representation
  5. Calculation-Friendly: Easy date arithmetic

Use Cases

  • Log file timestamps
  • Database record creation times
  • API request/response timestamps
  • Session expiration times
  • File modification dates
  • Event scheduling

Timestamp Formats

Unix Timestamp (Seconds)

1735689600

Used by: PHP, Python, C, most Unix systems

Unix Timestamp (Milliseconds)

1735689600000

Used by: JavaScript, Java, many APIs

ISO 8601 Format

2025-01-01T00:00:00Z
2025-01-01T00:00:00+00:00

Standard international format, used in JSON APIs

RFC 2822 Format

Wed, 01 Jan 2025 00:00:00 +0000

Used in email headers, HTTP dates

Human-Readable Formats

January 1, 2025 12:00 AM
01/01/2025 00:00:00
2025-01-01 00:00:00

Converting Timestamps

Unix to Human-Readable

JavaScript

const timestamp = 1735689600;
const date = new Date(timestamp * 1000);
console.log(date.toLocaleString());

Python

import datetime
timestamp = 1735689600
date = datetime.datetime.fromtimestamp(timestamp)
print(date.strftime('%Y-%m-%d %H:%M:%S'))

PHP

$timestamp = 1735689600;
echo date('Y-m-d H:i:s', $timestamp);

Human-Readable to Unix

JavaScript

const date = new Date('2025-01-01T00:00:00Z');
const timestamp = Math.floor(date.getTime() / 1000);

Python

import datetime
date = datetime.datetime(2025, 1, 1, 0, 0, 0)
timestamp = int(date.timestamp())

PHP

$date = '2025-01-01 00:00:00';
$timestamp = strtotime($date);

Working with Timezones

Important Concepts

  • Unix timestamps are always UTC
  • Timezone conversion happens during display
  • Store timestamps in UTC, display in local timezone

JavaScript Timezone Handling

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

// Convert to specific timezone
const options = {
  timeZone: 'America/New_York',
  year: 'numeric',
  month: '2-digit',
  day: '2-digit',
  hour: '2-digit',
  minute: '2-digit',
  second: '2-digit'
};
const formatted = new Date(now * 1000).toLocaleString('en-US', options);

Python Timezone Handling

from datetime import datetime
import pytz

# Create timezone-aware datetime
utc = pytz.UTC
eastern = pytz.timezone('US/Eastern')

# Convert
utc_time = datetime.now(utc)
eastern_time = utc_time.astimezone(eastern)

Common Timestamp Operations

Current Timestamp

JavaScript

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

Python

import time
now = int(time.time())

PHP

$now = time();

MySQL

SELECT UNIX_TIMESTAMP();

Adding/Subtracting Time

JavaScript

const timestamp = 1735689600;
const tomorrow = timestamp + (24 * 60 * 60); // +1 day
const lastWeek = timestamp - (7 * 24 * 60 * 60); // -7 days

Python

from datetime import datetime, timedelta
timestamp = 1735689600
date = datetime.fromtimestamp(timestamp)
tomorrow = date + timedelta(days=1)

Time Differences

const start = 1735689600;
const end = 1735776000;
const diffSeconds = end - start;
const diffHours = diffSeconds / 3600;
const diffDays = diffSeconds / 86400;

Database Timestamps

MySQL/MariaDB

-- Store as integer
CREATE TABLE events (
  id INT,
  created_at INT,
  INDEX idx_created (created_at)
);

-- Or use TIMESTAMP type
CREATE TABLE events (
  id INT,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Convert to Unix timestamp
SELECT UNIX_TIMESTAMP(created_at) FROM events;

PostgreSQL

-- Store as integer
CREATE TABLE events (
  id SERIAL,
  created_at BIGINT
);

-- Or use TIMESTAMP
CREATE TABLE events (
  id SERIAL,
  created_at TIMESTAMP DEFAULT NOW()
);

-- Convert to Unix timestamp
SELECT EXTRACT(EPOCH FROM created_at)::INTEGER FROM events;

MongoDB

// MongoDB uses milliseconds
db.events.insertOne({
  name: "Event",
  created_at: new Date()
});

// Query by timestamp
db.events.find({
  created_at: { $gte: new Date(1735689600000) }
});

Best Practices

1. Always Store in UTC

  • Store all timestamps in UTC
  • Convert to local timezone only for display
  • Avoid timezone-specific storage

2. Use Consistent Units

  • Choose seconds OR milliseconds
  • Document which unit you're using
  • Be consistent across your application

3. Handle Timezones Properly

  • Never assume user's timezone
  • Let users select their timezone
  • Display times with timezone indicator

4. Consider Precision

  • Seconds: sufficient for most applications
  • Milliseconds: needed for high-precision logging
  • Microseconds: used in performance monitoring

5. Validate Timestamps

function isValidTimestamp(timestamp) {
  // Check if reasonable (between 1970 and 2100)
  return timestamp > 0 && timestamp < 4102444800;
}

Common Mistakes

1. Mixing Seconds and Milliseconds

// Wrong
const date = new Date(1735689600); // Missing * 1000

// Correct
const date = new Date(1735689600 * 1000);

2. Forgetting Timezone Conversion

// Wrong - assumes local timezone
const date = new Date('2025-01-01 00:00:00');

// Correct - explicit UTC
const date = new Date('2025-01-01T00:00:00Z');

3. Year 2038 Problem

  • 32-bit systems can't represent dates after 2038
  • Use 64-bit timestamps for future dates
  • Consider using BIGINT in databases

Timestamp Ranges

Minimum and Maximum Values

32-bit (seconds)

  • Min: -2,147,483,648 (December 13, 1901)
  • Max: 2,147,483,647 (January 19, 2038)

64-bit (seconds)

  • Practically unlimited range
  • Recommended for all new applications

Use Our Timestamp Converter

Our free online tool provides:

  • Instant conversions
  • Multiple format support
  • Timezone handling
  • Batch conversion
  • Human-readable output
  • Copy to clipboard

Convert timestamps effortlessly today!

Keywords

timestamp converter
unix timestamp
epoch converter
unix time
timestamp to date
epoch time converter