Unix timestamps are integers counting seconds since January 1, 1970, 00:00:00 UTC. They appear in log files, databases, APIs, cookies, and JWT tokens. This reference covers everything you need to work with them in any language.
The Basics
A Unix timestamp is a single number — no timezone, no formatting, no ambiguity. The current timestamp (as of mid-2024) is around 1,717,000,000. It grows by 1 every second.
Seconds vs milliseconds is the biggest source of bugs: Unix timestamps are in seconds (10 digits), but JavaScript's Date.now() and Java's System.currentTimeMillis() return milliseconds (13 digits). Always check which unit your source uses.
JavaScript
``javascript
// Timestamp → date
const date = new Date(1717200000 * 1000); // multiply by 1000!
console.log(date.toISOString()); // "2024-05-31T16:00:00.000Z"
console.log(date.toLocaleString()); // local time
// Current timestamp (seconds)
const now = Math.floor(Date.now() / 1000);
// Today's midnight UTC
const midnight = Math.floor(new Date().setUTCHours(0,0,0,0) / 1000);
`
Python
`python
import datetime, time
Timestamp → datetime (timezone-aware, recommended)
dt = datetime.datetime.fromtimestamp(
1717200000, tz=datetime.timezone.utc
)
print(dt) # 2024-05-31 16:00:00+00:00
Current timestamp
print(int(time.time()))
Format
print(dt.strftime('%Y-%m-%d %H:%M:%S'))
`
PHP
`php
echo date('Y-m-d H:i:s', 1717200000); // local time
echo gmdate('Y-m-d H:i:s', 1717200000); // UTC always
// Current timestamp
echo time();
`
Go
`go
t := time.Unix(1717200000, 0).UTC()
fmt.Println(t.Format(time.RFC3339)) // "2024-05-31T16:00:00Z"
now := time.Now().Unix()
`
Ruby
<code>ruby
<p>Time.at(1717200000).utc # => 2024-05-31 16:00:00 UTC</p>
<p>Time.now.to_i # current timestamp</p>
</code>
C# (.NET)
`csharp
// Timestamp → DateTime
var dt = DateTimeOffset.FromUnixTimeSeconds(1717200000).UtcDateTime;
// Current timestamp
long now = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
`
Java
`java
Instant instant = Instant.ofEpochSecond(1717200000L);
LocalDateTime dt = LocalDateTime.ofInstant(instant, ZoneOffset.UTC);
long now = Instant.now().getEpochSecond();
`
SQL
`sql
-- MySQL
SELECT FROM_UNIXTIME(1717200000); -- '2024-05-31 16:00:00'
SELECT UNIX_TIMESTAMP(); -- current
-- PostgreSQL
SELECT to_timestamp(1717200000); -- 2024-05-31 16:00:00+00
SELECT EXTRACT(EPOCH FROM NOW()); -- current
`
Shell (Bash)
<code>bash
<p>date -d @1717200000 # Linux (GNU date)</p>
<p>date -r 1717200000 # macOS (BSD date)</p>
<p>date +%s # current timestamp</p>
</code>
Key Pitfalls
1. Local time vs UTC: datetime.fromtimestamp() in Python and Date() in JavaScript both apply local timezone by default. Always pass UTC explicitly when it matters.
2. The Year 2038 problem: 32-bit signed integers overflow at timestamp 2147483647 (January 19, 2038). Use BIGINT in databases and 64-bit integers in code.
3. Timestamp 0: This is a valid date (January 1, 1970) — not "no date". Don't reject it as invalid.
4. Negative timestamps: Valid! They represent dates before 1970. Timestamp -86400` = December 31, 1969.
Quick Reference: Common Timestamp Values
| Timestamp | Date (UTC) |
|-----------|-----------|
| 0 | 1970-01-01 00:00:00 |
| 86400 | 1970-01-02 00:00:00 (one day later) |
| 1000000000 | 2001-09-09 01:46:40 |
| 1700000000 | 2023-11-14 22:13:20 |
| 2147483647 | 2038-01-19 03:14:07 (32-bit max) |
Need to convert a timestamp without writing code? Use the free Unix Timestamp Converter — converts in both directions, shows the live current timestamp, and supports all timezones.