# Timestamp Conversion Guide: Unix, ISO 8601, and Human-Readable Formats
Converting between timestamp formats is a common task in development. This tutorial covers practical conversions between Unix timestamps, ISO 8601, and human-readable dates. For instant conversions, use our Timestamp Converter.
Understanding the Formats
Unix Timestamp (Seconds)
1720425600
The original Unix format. A single integer representing seconds since the epoch.
Unix Timestamp (Milliseconds)
1720425600000
Used by JavaScript, Java, and many web APIs. Same as seconds × 1000.
ISO 8601
2024-07-08T10:00:00.000Z
2024-07-08T10:00:00+08:00
The international standard for date and time representation. The Z suffix indicates UTC. Offset notation (+08:00) specifies a timezone.
RFC 2822
Mon, 08 Jul 2024 10:00:00 GMT
Used in email headers and HTTP headers.
Human-Readable
July 8, 2024 10:00:00 AM UTC
2024-07-08 10:00:00
08/07/2024 10:00 AM
Conversion: Unix Timestamp → Human-Readable
JavaScript
// Unix timestamp in seconds
const ts = 1720425600;
// Convert to Date object
const date = new Date(ts * 1000); // Multiply by 1000!
// Format as string
console.log(date.toISOString()); // 2024-07-08T10:00:00.000Z
console.log(date.toUTCString()); // Mon, 08 Jul 2024 10:00:00 GMT
console.log(date.toLocaleString()); // Local time format
Python
from datetime import datetime, timezone
ts = 1720425600
# Convert to datetime
dt = datetime.fromtimestamp(ts, tz=timezone.utc)
# Format as string
print(dt.isoformat()) # 2024-07-08T10:00:00+00:00
print(dt.strftime('%Y-%m-%d %H:%M:%S')) # 2024-07-08 10:00:00
Go
ts := int64(1720425600)
t := time.Unix(ts, 0)
fmt.Println(t.Format(time.RFC3339)) // 2024-07-08T10:00:00Z
fmt.Println(t.Format("2006-01-02 15:04:05")) // 2024-07-08 10:00:00
Conversion: Human-Readable → Unix Timestamp
JavaScript
// From ISO string
const date1 = new Date('2024-07-08T10:00:00Z');
const ts1 = Math.floor(date1.getTime() / 1000);
console.log(ts1); // 1720425600
// From custom format
const date2 = new Date('2024-07-08 10:00:00 UTC');
const ts2 = Math.floor(date2.getTime() / 1000);
Python
from datetime import datetime, timezone
# From ISO string
dt = datetime.fromisoformat('2024-07-08T10:00:00+00:00')
ts = int(dt.timestamp())
print(ts) # 1720425600
# From custom format
dt = datetime.strptime('2024-07-08 10:00:00', '%Y-%m-%d %H:%M:%S')
dt = dt.replace(tzinfo=timezone.utc)
ts = int(dt.timestamp())
Go
layout := "2006-01-02 15:04:05"
t, _ := time.Parse(layout, "2024-07-08 10:00:00")
ts := t.Unix()
fmt.Println(ts) // 1720425600
Conversion: ISO 8601 ↔ Unix Timestamp
ISO 8601 to Unix
const iso = '2024-07-08T10:00:00.000Z';
const date = new Date(iso);
const ts = Math.floor(date.getTime() / 1000);
console.log(ts); // 1720425600
Unix to ISO 8601
const ts = 1720425600;
const iso = new Date(ts * 1000).toISOString();
console.log(iso); // 2024-07-08T10:00:00.000Z
Working with Timezones
Convert UTC Timestamp to Local Time
const ts = 1720425600;
const date = new Date(ts * 1000);
// Display in specific timezone
const options = {
timeZone: 'Asia/Shanghai',
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
console.log(date.toLocaleString('zh-CN', options));
// 2024/07/08 18:00:00
Convert Local Time to UTC Timestamp
from datetime import datetime, timezone, timedelta
# Local time (Shanghai, UTC+8)
local_dt = datetime(2024, 7, 8, 18, 0, 0)
shanghai_tz = timezone(timedelta(hours=8))
local_dt = local_dt.replace(tzinfo=shanghai_tz)
# Convert to UTC timestamp
ts = int(local_dt.timestamp())
print(ts) # 1720425600
Common Conversion Pitfalls
1. Seconds vs Milliseconds
// ❌ Wrong: treating seconds as milliseconds
const date = new Date(1720425600);
// Date is Jan 20, 1970
// ✅ Correct: multiply by 1000
const date = new Date(1720425600 * 1000);
// Date is Jul 8, 2024
2. Timezone Confusion
# ❌ Wrong: assumes local timezone
import time
ts = int(time.mktime(time.strptime('2024-07-08 10:00:00', '%Y-%m-%d %H:%M:%S')))
# ✅ Correct: explicitly set UTC
from datetime import datetime, timezone
dt = datetime(2024, 7, 8, 10, 0, 0, tzinfo=timezone.utc)
ts = int(dt.timestamp())
3. Leap Seconds
Unix timestamps don't account for leap seconds. Every day is treated as exactly 86,400 seconds. This means:
- Timestamps during leap seconds are ambiguous
- Most systems handle this gracefully by ignoring leap seconds
- For precise time calculations, use TAI (International Atomic Time) instead
Batch Conversion Script
Here's a utility script for batch converting timestamps:
function batchConvert(timestamps) {
return timestamps.map(ts => {
const seconds = ts > 1e12 ? Math.floor(ts / 1000) : ts;
const date = new Date(seconds * 1000);
return {
timestamp: seconds,
iso8601: date.toISOString(),
utc: date.toUTCString(),
local: date.toLocaleString()
};
});
}
// Usage
const results = batchConvert([1720425600, 1720512000, 1720598400]);
console.table(results);
Conclusion
Timestamp conversion is a fundamental skill for developers. Whether you're working with APIs, databases, or log files, you'll encounter timestamps in various formats. Understanding how to convert between Unix timestamps, ISO 8601, and human-readable formats — while being mindful of seconds vs milliseconds and timezone handling — will save you countless hours of debugging. For quick, accurate conversions, our Timestamp Converter handles all the edge cases for you.