Unix timestamp datetime conversion
DateTime APIs

Unix Timestamp Guide: DateTime Format Conversion

📅 March 5, 2026 ⏱️ 7 min read 🏷️ DateTime, Unix, APIs

Unix timestamps are everywhere — APIs, databases, JWT tokens, log files, cron jobs. Understanding how to convert between epoch time and human-readable formats is a crucial developer skill.

What is a Unix Timestamp?

A Unix timestamp (or epoch time) counts the number of seconds since January 1, 1970 00:00:00 UTC. It's a single integer that represents an exact moment in time, timezone-independent.

1772694478     → seconds since epoch
1772694478000  → milliseconds (JavaScript)
1772694478000000 → microseconds (some databases)

// All represent: March 5, 2026 07:07:58 UTCTimestamps

DateTime Format Reference

Format Example Used By
Unix (seconds) 1772694478 APIs, databases, PHP
Unix (ms) 1772694478000 JavaScript, Java
ISO 8601 2026-03-05T07:07:58Z JSON APIs, HTML datetime
RFC 2822 Thu, 05 Mar 2026 07:07:58 +0000 Email headers, HTTP
Human March 5, 2026 7:07 AM UI display

JavaScript Conversion

// Unix seconds → Date
const date = new Date(1772694478 * 1000);

// Date → Unix seconds
const unix = Math.floor(Date.now() / 1000);

// ISO 8601
date.toISOString(); // "2026-03-05T07:07:58.000Z"

// Locale string
date.toLocaleString('en-US', {
  dateStyle: 'full',
  timeStyle: 'long'
}); // "Thursday, March 5, 2026 at 7:07:58 AM UTC"JavaScript

C# / .NET Conversion

// Unix seconds → DateTimeOffset
var dto = DateTimeOffset.FromUnixTimeSeconds(1772694478);
// → 2026-03-05T07:07:58+00:00

// DateTimeOffset → Unix seconds
long unix = dto.ToUnixTimeSeconds();

// ISO 8601
dto.ToString("o"); // "2026-03-05T07:07:58.0000000+00:00"

// Custom format
dto.ToString("MMMM d, yyyy h:mm tt");
// → "March 5, 2026 7:07 AM"C#

Python Conversion

from datetime import datetime, timezone

# Unix → datetime
dt = datetime.fromtimestamp(1772694478, tz=timezone.utc)

# datetime → Unix
unix = int(dt.timestamp())

# ISO 8601
dt.isoformat()  # "2026-03-05T07:07:58+00:00"

# Custom format
dt.strftime("%B %d, %Y %I:%M %p")
# → "March 05, 2026 07:07 AM"Python
💡 Pro Tip

Always store timestamps in UTC. Convert to local timezone only at the UI layer. This prevents timezone-related bugs in distributed systems and makes data portable across regions.

⚠️ Year 2038 Problem

32-bit systems store Unix timestamps as signed 32-bit integers, which overflow on January 19, 2038. Use 64-bit timestamps (long in C#, default in modern JS/Python) to avoid this.

🕐

Try DateTime Converter

Paste any timestamp or date string — get instant conversions to all formats. Auto-detects input.

Open DateTime Converter →