Timestamp to Date — How to Convert Any Timestamp to a Readable Date
To convert a timestamp to a date, divide by 1,000 if it is in milliseconds (13 digits) to get seconds (10 digits), then use your language's built-in conversion function — in JavaScript use new Date(timestamp * 1000), in Python use datetime.utcfromtimestamp(timestamp), and in PHP use gmdate('Y-m-d H:i:s', timestamp). For instant conversion without code use the Unix Timestamp Converter.
A Unix timestamp is a count of seconds (or milliseconds) since January 1 1970 at 00:00:00 UTC — converting it to a readable date requires your programming language to translate that raw integer into a year, month, day, and time string.
How Do You Know If Your Timestamp Is in Seconds or Milliseconds?
Before converting, always check the digit count:
| Digit Count | Unit | Example | Action Needed |
|---|---|---|---|
| 10 digits | Seconds | 1,783,941,653 | Use directly |
| 13 digits | Milliseconds | 1,783,941,653,000 | Divide by 1,000 first |
| 16 digits | Microseconds | 1,783,941,653,000,000 | Divide by 1,000,000 first |
| 19 digits | Nanoseconds | 1,783,941,653,000,000,000 | Divide by 1,000,000,000 first |
The quick rule: 10 digits = seconds. 13 digits = milliseconds. If you use a 13-digit value where 10 digits are expected, the output will show a date thousands of years in the future. If you use a 10-digit value where 13 digits are expected, the output will show a date very close to January 1 1970.
JavaScript's Date.now() and Java's System.currentTimeMillis() return milliseconds by default. Python's time.time(), PHP's time(), and Unix shell date +%s return seconds by default.
How Do You Convert a Timestamp to a Date in JavaScript?
JavaScript's Date constructor expects milliseconds — always multiply seconds by 1,000 before passing to new Date().
Convert seconds to date:
const epochSeconds = 1783941653;
const date = new Date(epochSeconds * 1000);
console.log(date.toUTCString());
console.log(date.toISOString());
console.log(date.toLocaleDateString());
Convert milliseconds to date (Date.now() output):
const epochMilliseconds = Date.now();
const date = new Date(epochMilliseconds);
console.log(date.toUTCString());
Auto-detect seconds vs milliseconds:
function timestampToDate(ts) {
const epochMs = ts.toString().length === 13 ? ts : ts * 1000;
return new Date(epochMs);
}
console.log(timestampToDate(1783941653).toUTCString());
console.log(timestampToDate(1783941653000).toUTCString());
Format as a specific date string:
const epochSeconds = 1783941653;
const date = new Date(epochSeconds * 1000);
const formatted = date.toISOString().split('T')[0];
console.log(formatted);
How Do You Convert a Timestamp to a Date in Python?
Python's time.time() returns seconds as a float. Use datetime.utcfromtimestamp() for UTC output or datetime.fromtimestamp() for local time output.
Convert to UTC date (recommended):
import datetime
epoch_seconds = 1783941653
dt_utc = datetime.datetime.utcfromtimestamp(epoch_seconds)
print(dt_utc)
Convert to UTC with explicit timezone (best practice):
import datetime
epoch_seconds = 1783941653
dt = datetime.datetime.fromtimestamp(
epoch_seconds,
tz=datetime.timezone.utc
)
print(dt.strftime('%Y-%m-%d %H:%M:%S'))
Convert milliseconds to date:
import datetime
epoch_milliseconds = 1783941653000
epoch_seconds = epoch_milliseconds / 1000
dt_utc = datetime.datetime.utcfromtimestamp(epoch_seconds)
print(dt_utc)
Get current timestamp and convert back:
import time
import datetime
current = int(time.time())
dt = datetime.datetime.utcfromtimestamp(current)
print(f"Unix timestamp: {current}")
print(f"Readable date: {dt}")
How Do You Convert a Timestamp to a Date in PHP?
PHP's date() function applies the server's local timezone — always use gmdate() for consistent UTC output.
Convert to UTC date string:
$epoch_seconds = 1783941653;
echo gmdate("Y-m-d H:i:s", $epoch_seconds);
Convert to formatted date with timezone:
$epoch_seconds = 1783941653;
$dt = new DateTime('@' . $epoch_seconds);
$dt->setTimezone(new DateTimeZone('UTC'));
echo $dt->format('Y-m-d H:i:s');
Convert milliseconds to date:
$epoch_milliseconds = 1783941653000;
$epoch_seconds = intval($epoch_milliseconds / 1000);
echo gmdate("Y-m-d H:i:s", $epoch_seconds);
Using DateTimeImmutable (recommended for new code):
$epoch_seconds = 1783941653;
$dt = new DateTimeImmutable('@' . $epoch_seconds);
echo $dt->format('Y-m-d H:i:s') . ' UTC';
How Do You Convert a Timestamp to a Date in SQL?
PostgreSQL:
SELECT TO_TIMESTAMP(1783941653);
SELECT TO_TIMESTAMP(1783941653) AT TIME ZONE 'UTC';
SELECT TO_CHAR(TO_TIMESTAMP(1783941653), 'YYYY-MM-DD HH24:MI:SS');
MySQL:
SELECT FROM_UNIXTIME(1783941653);
SELECT FROM_UNIXTIME(1783941653, '%Y-%m-%d %H:%i:%s');
SELECT CONVERT_TZ(FROM_UNIXTIME(1783941653), 'SYSTEM', 'UTC');
SQLite:
SELECT datetime(1783941653, 'unixepoch');
SELECT datetime(1783941653, 'unixepoch', 'localtime');
SQL Server:
SELECT DATEADD(SECOND, 1783941653, '1970-01-01');
How Do You Convert a Timestamp to a Date in Java?
Using Instant (Java 8+, recommended):
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
long epochSeconds = 1783941653L;
Instant instant = Instant.ofEpochSecond(epochSeconds);
String formatted = DateTimeFormatter.ISO_INSTANT.format(instant);
System.out.println(formatted);
Using LocalDateTime:
import java.time.LocalDateTime;
import java.time.ZoneOffset;
long epochSeconds = 1783941653L;
LocalDateTime dt = LocalDateTime.ofEpochSecond(
epochSeconds, 0, ZoneOffset.UTC
);
System.out.println(dt);
Converting milliseconds:
import java.time.Instant;
long epochMilliseconds = 1783941653000L;
Instant instant = Instant.ofEpochMilli(epochMilliseconds);
System.out.println(instant);
How Do You Convert a Timestamp to a Date in Excel?
Excel does not natively understand Unix timestamps — it uses its own date serial number system starting from January 1, 1900. To convert a Unix timestamp in cell A1 to an Excel date:
Formula for seconds:
=(A1/86400)+25569
Then format the cell as a Date or Date/Time to display it correctly.
Formula for milliseconds:
=(A1/86400000)+25569
How the formula works:
- Divide by
86400(seconds per day) to convert seconds to days - Add
25569(the number of days between January 1, 1900 and January 1, 1970) - Format the resulting cell as a Date or Date Time
For example, =(1783941653/86400)+25569 produces the Excel serial number for July 17, 2026.
How Do You Convert a Timestamp to a Date in Bash?
Linux (GNU date):
date -d @1783941653
date -d @1783941653 '+%Y-%m-%d %H:%M:%S'
date -d @1783941653 --utc '+%Y-%m-%d %H:%M:%S UTC'
macOS (BSD date):
date -r 1783941653
date -r 1783941653 '+%Y-%m-%d %H:%M:%S'
Convert milliseconds in Bash:
epoch_ms=1783941653000
epoch_s=$((epoch_ms / 1000))
date -d @$epoch_s '+%Y-%m-%d %H:%M:%S UTC'
How Do You Convert a Timestamp to a Date in Go?
package main
import (
"fmt"
"time"
)
func main() {
epochSeconds := int64(1783941653)
t := time.Unix(epochSeconds, 0).UTC()
fmt.Println(t.Format("2006-01-02 15:04:05"))
}
How Do You Convert a Timestamp to a Date in Ruby?
epoch_seconds = 1783941653
time = Time.at(epoch_seconds).utc
puts time.strftime('%Y-%m-%d %H:%M:%S')
What Is the Timezone Trap When Converting Timestamps?
The most common real-world timestamp to date conversion bug is the timezone trap — conversion functions applying a local timezone instead of UTC without the developer noticing.
How it happens:
- PHP's
date()applies the server's local timezone — usegmdate()instead - Python's
datetime.fromtimestamp()without a timezone argument uses the system local timezone — usedatetime.utcfromtimestamp()or passtz=timezone.utc - MySQL's
FROM_UNIXTIME()converts to the server's local timezone — useCONVERT_TZ()to explicitly output UTC
The result: A timestamp stored in production in one timezone reads differently when the application moves to a new server, or when users in different locations view the same stored value.
The fix: Always convert to UTC at the data layer. Apply timezone conversion to local time only at the final display layer — and only when you know the user's timezone preference.
Timestamp to Date Quick Reference
| Language | Seconds to Date | Milliseconds to Date |
|---|---|---|
| JavaScript | new Date(ts * 1000).toUTCString() | new Date(ts).toUTCString() |
| Python | datetime.utcfromtimestamp(ts) | datetime.utcfromtimestamp(ts/1000) |
| PHP | gmdate('Y-m-d H:i:s', ts) | gmdate('Y-m-d H:i:s', ts/1000) |
| Java | Instant.ofEpochSecond(ts) | Instant.ofEpochMilli(ts) |
| SQL (PostgreSQL) | TO_TIMESTAMP(ts) | TO_TIMESTAMP(ts/1000) |
| SQL (MySQL) | FROM_UNIXTIME(ts) | FROM_UNIXTIME(ts/1000) |
| Bash (Linux) | date -d @ts | date -d @$((ts/1000)) |
| Go | time.Unix(ts, 0).UTC() | time.UnixMilli(ts).UTC() |
| Ruby | Time.at(ts).utc | Time.at(ts/1000.0).utc |
| Excel | =(ts/86400)+25569 | =(ts/86400000)+25569 |
Common Mistakes to Avoid
- Using a 13-digit milliseconds value where 10-digit seconds are expected. The output shows a date in the year 56,000. Always check digit count — 10 = seconds, 13 = milliseconds. Divide by 1,000.
- Forgetting to multiply by 1,000 in JavaScript.
new Date(epochSeconds)requires milliseconds — always usenew Date(epochSeconds * 1000)when your input is in seconds. - Using date() instead of gmdate() in PHP.
date()applies the server's local timezone — usegmdate()for consistent UTC output across all server environments. - Using datetime.fromtimestamp() without timezone in Python. Without an explicit timezone argument, this function uses the system local timezone — producing output that varies by server location.
- Not formatting the cell in Excel. After applying the formula
=(ts/86400)+25569the cell displays a decimal number until you format it as a Date or Date/Time cell type. - Storing local time in the database. Always store the raw Unix timestamp or a UTC date string — never a local time value. Apply timezone conversion only at the display layer.
Related Guides
- What Is a Unix Timestamp?
- Unix Timestamp — Complete Guide
- What Is Epoch Time?
- Date to Unix Timestamp — Complete Guide
- Unix Timestamp Code Examples
Convert any timestamp to a date instantly with the Unix Timestamp Converter, or generate a Discord timestamp from any date with the Discord Timestamp Generator.
Frequently Asked Questions
Ready to generate Discord timestamps?
Open the Generator