How to Convert Multiple Unix Timestamps at Once
Why Batch Convert Timestamps?
When you work with server logs, database exports, API responses, or analytics datasets, you rarely encounter a single timestamp at a time. Real-world data often contains thousands or millions of Unix timestamps spread across files, columns, or JSON payloads. Manually converting each one is impractical. Batch processing turns mountains of raw numbers into readable timelines.
This guide covers practical approaches for converting multiple timestamps using command-line tools, scripts, and our online tool.
Method 1: Using the Online Batch Converter
Our Unix Timestamp Converter supports batch input. Paste multiple timestamps (one per line or comma-separated) and the tool converts all of them at once, displaying the results in a table sorted by timezone.
This is ideal for moderate-sized batches โ dozens to hundreds of timestamps โ where you need a quick, visual result without writing code.
Method 2: Command-Line Batch Processing
Basic Loop with the date Command
# Convert a list of timestamps using a bash loop
for ts in 1785292800 1785379200 1785465600 1785552000; do
date -d @"$ts" "+%Y-%m-%d %H:%M:%S"
done
Reading from a File
# timestamps.txt contains one timestamp per line
while read -r ts; do
date -d @"$ts" "+%Y-%m-%d %H:%M:%S"
done < timestamps.txt
Using xargs for Parallel Processing
# For large files, use xargs with multiple processes
cat timestamps.txt | xargs -P 4 -I {} date -d "@{}" "+%Y-%m-%d %H:%M:%S"
Output to a CSV File
# Generate a CSV with original timestamp and converted date
echo "timestamp,date_utc,date_local" > output.csv
while read -r ts; do
utc_date=$(TZ=UTC date -d @"$ts" "+%Y-%m-%d %H:%M:%S")
local_date=$(date -d @"$ts" "+%Y-%m-%d %H:%M:%S")
echo "$ts,$utc_date,$local_date" >> output.csv
done < timestamps.txt
Method 3: Extracting Timestamps from Log Files
Log files often contain timestamps embedded in structured or semi-structured text. Here are practical techniques for common log formats.
Apache / Nginx Access Logs
Apache and Nginx logs often use the %{%Y-%m-%d}T format or, if configured, Unix timestamps:
# Extract and convert timestamps from an Nginx log
# The log lines might contain: [1785292800] GET /index.html 200
grep -oP '\[\K[0-9]{10}(?=\])' access.log | while read -r ts; do
date -d @"$ts" "+%Y-%m-%d %H:%M:%S"
done
JSON Logs
Modern applications often log in JSON format:
# Using jq to extract timestamps from a JSON log file
cat app.log | jq -r '.timestamp' | while read -r ts; do
date -d @"$ts" "+%Y-%m-%d %H:%M:%S"
done
Custom Delimited Logs
# If timestamps are the first field in a log (pipe-delimited)
awk -F'|' '{ts=$1; cmd="date -d @" ts " \"+%Y-%m-%d %H:%M:%S\""; cmd | getline date; close(cmd); print date, $0}' server.log
Method 4: Using Python for Advanced Batch Processing
Python is the most flexible tool for batch conversion, especially when timestamps need filtering, transformation, or export.
Convert a List of Timestamps
from datetime import datetime
import json
timestamps = [1785292800, 1785379200, 1785465600, 1785552000]
results = []
for ts in timestamps:
dt = datetime.utcfromtimestamp(ts)
results.append({
"timestamp": ts,
"datetime_utc": dt.strftime("%Y-%m-%d %H:%M:%S"),
"date": dt.strftime("%Y-%m-%d"),
"time": dt.strftime("%H:%M:%S"),
"day_of_week": dt.strftime("%A"),
})
print(json.dumps(results, indent=2))
Process a CSV File
import csv
from datetime import datetime
with open("data.csv", "r") as infile, open("converted.csv", "w", newline="") as outfile:
reader = csv.DictReader(infile)
writer = csv.DictWriter(outfile, fieldnames=reader.fieldnames + ["date_utc", "date_local"])
writer.writeheader()
for row in reader:
ts = int(row["timestamp"])
dt_utc = datetime.utcfromtimestamp(ts)
row["date_utc"] = dt_utc.strftime("%Y-%m-%d %H:%M:%S")
# You can replace this with your local timezone
from datetime import timezone
dt_local = datetime.fromtimestamp(ts, tz=timezone.utc).astimezone()
row["date_local"] = dt_local.strftime("%Y-%m-%d %H:%M:%S %Z")
writer.writerow(row)
print("Conversion complete. Output written to converted.csv")
Filter by Date Range
from datetime import datetime
# Define the range: start and end of July 2026
start_ts = int(datetime(2026, 7, 1).timestamp())
end_ts = int(datetime(2026, 7, 31, 23, 59, 59).timestamp())
timestamps = [1785292800, 1785379200, 1785465600, 1785552000,
1234567890, 1000000000]
# Filter to July 2026 only
july_only = [ts for ts in timestamps if start_ts <= ts <= end_ts]
for ts in july_only:
dt = datetime.utcfromtimestamp(ts)
print(f"{ts} -> {dt.strftime('%Y-%m-%d %H:%M:%S')}")
Method 5: Using awk for Streaming Conversion
For very large files (millions of rows), awk processes data as a stream without loading everything into memory:
#!/usr/bin/awk -f
# batch-convert.awk
# Converts first field as Unix timestamp, prints all fields with date
{
ts = $1
# awk's mktime expects "YYYY MM DD HH MM SS"
# We call the shell for conversion via date command
cmd = "date -d @" ts " \"+%Y-%m-%d %H:%M:%S\""
cmd | getline date
close(cmd)
print date, $0
}
Usage:
./batch-convert.awk server.log
Method 6: Using SQL for Database Timestamps
If your timestamps are in a database, let SQL do the work:
PostgreSQL
SELECT
id,
event_time,
to_timestamp(event_time) AS readable_time,
to_char(to_timestamp(event_time), 'YYYY-MM-DD HH24:MI:SS') AS formatted_time
FROM events
WHERE to_timestamp(event_time) >= '2026-07-01';
MySQL
SELECT
id,
event_time,
FROM_UNIXTIME(event_time) AS readable_time,
FROM_UNIXTIME(event_time, '%Y-%m-%d %H:%i:%s') AS formatted_time
FROM events
WHERE FROM_UNIXTIME(event_time) >= '2026-07-01';
SQLite
SELECT
id,
event_time,
datetime(event_time, 'unixepoch') AS readable_time,
strftime('%Y-%m-%d %H:%M:%S', event_time, 'unixepoch') AS formatted_time
FROM events;
Formatting Output Tables
# Create a nicely formatted table with column headers
convert() {
printf "%-15s %-25s %-25s\n" "TIMESTAMP" "UTC" "LOCAL"
printf "%-15s %-25s %-25s\n" "---------------" "-------------------------" "-------------------------"
while read -r ts; do
utc=$(TZ=UTC date -d @"$ts" "+%Y-%m-%d %H:%M:%S")
local=$(date -d @"$ts" "+%Y-%m-%d %H:%M:%S")
printf "%-15s %-25s %-25s\n" "$ts" "$utc" "$local"
done <<< "$(cat "$1")"
}
Performance Comparison
| Method | Best For | Speed (10K timestamps) | Complexity | |--------|----------|----------------------|------------| | Online converter | Small batches (< 50) | Instant | None | | Bash loop | Small-med (50-10K) | ~30s | Low | | xargs parallel | Medium (10K-100K) | ~10s | Low | | Python | Any size | ~2s | Medium | | awk stream | Very large (millions) | ~5s | Medium | | SQL | Database data | Instant | Low |
For quick, everyday batches, use our Unix Timestamp Converter. For automation and large datasets, script the conversion using the programming approach that matches your workflow.