Unix Timestamp: Epoch Time Examples
If you work with databases, APIs, or server logs, you have probably seen Unix timestamps. They appear in log files, API responses, cookies, scheduled jobs, and many storage systems.
This guide explains what Unix timestamps are, why they are useful, and how to convert them in common programming languages.
What Is a Unix Timestamp?
A Unix timestamp is the number of seconds that have elapsed since January 1, 1970, 00:00:00 UTC. This starting point is called the Unix Epoch.
1716763574That value represents one exact moment in time. It does not change based on the viewer’s timezone.
Why Use Unix Timestamps?
Unix timestamps are useful because they are timezone-independent, compact, and easy to compare.
- To find the difference between two dates, subtract two timestamps.
- To add seven days, add
604800seconds. - To store a moment in a database, save one integer instead of a formatted string.
Getting the Current Timestamp
| Language | Code |
|---|---|
| JavaScript | Math.floor(Date.now() / 1000) |
| Python | int(time.time()) |
| PHP | time() |
| Java | System.currentTimeMillis() / 1000 |
| Go | time.Now().Unix() |
| Ruby | Time.now.to_i |
| Shell | date +%s |
| MySQL | SELECT UNIX_TIMESTAMP(NOW()) |
| SQLite | SELECT strftime('%s', 'now') |
Seconds vs Milliseconds
Most Unix timestamps use seconds, but JavaScript Date.now() returns milliseconds.
Seconds: 1716763574
Milliseconds: 1716763574000If a timestamp has 13 digits, it is probably in milliseconds. If it has 10 digits, it is probably in seconds.
UTC, Local Time, and Display
A Unix timestamp represents a moment in UTC. The same timestamp can display as different calendar dates depending on timezone.
For example, a timestamp close to midnight UTC may appear as the previous or next day for users in other regions. This is not a conversion bug. It is the difference between storing an instant and displaying that instant locally.
For APIs and databases, store timestamps in UTC. For user interfaces, convert to the user’s timezone at the edge where the value is displayed.
JavaScript Conversion
const timestamp = 1716763574;
const date = new Date(timestamp * 1000);
console.log(date.toISOString());
const now = Math.floor(Date.now() / 1000);Python Conversion
from datetime import datetime
import time
timestamp = 1716763574
dt = datetime.fromtimestamp(timestamp)
print(dt)
current_timestamp = int(time.time())PHP Conversion
echo date('Y-m-d H:i:s', 1716763574);
echo strtotime('2024-05-26 22:06:14');Common Timestamp Values
| Date | Timestamp |
|---|---|
| Unix Epoch, January 1, 1970 | 0 |
| Y2K, January 1, 2000 | 946684800 |
| End of 32-bit signed timestamp range | 2147483647 |
The 32-bit limit falls on January 19, 2038. Modern systems generally use 64-bit values, but older systems can still be affected by the Year 2038 problem.
Timestamp Fields in APIs
API timestamp fields often use names such as:
created_atupdated_atexpires_atiatexpnbf
JWT tokens commonly use iat, exp, and nbf as Unix timestamps in seconds. If a token appears expired too early or too late, check whether the value was treated as seconds or milliseconds.
Use the JWT Decoder to inspect token claims and the Timestamp Converter to convert the values.
Common Timestamp Debugging Mistakes
The most common timestamp bug is treating seconds as milliseconds or milliseconds as seconds. A 10-digit value and a 13-digit value can both look like “just a number” until they are converted.
Watch for these signs:
- a modern event appears near 1970
- a date appears thousands of years in the future
- an expiration time is earlier than the issued time
- frontend and backend logs disagree by a factor of 1000
- a field name says
timestampwithout documenting the unit
When reviewing API fields, convert the value both ways if you are unsure. Then update the documentation or field name so the next person does not need to guess.
Practical Tips
- Store timestamps in UTC.
- Convert to local time only at the display layer.
- Document whether your API uses seconds or milliseconds.
- Validate timestamps before converting user input.
- Be careful with date-only values, which may not represent a precise moment.
- Include timezone information when showing readable dates in logs or reports.
Convert Timestamps Instantly
Use the Timestamp Converter to convert between Unix timestamps and readable dates. It supports seconds and milliseconds and runs in your browser.
Conclusion
Unix timestamps are a simple, universal way to represent time in software. Once you understand seconds, milliseconds, and UTC, they become much easier to work with across APIs, databases, and logs.
Related Guides
- Unix timestamp seconds vs milliseconds explains how to identify 10-digit and 13-digit timestamp values.
- Timestamp log debugging guide applies timestamp conversion to API and production log review.
- Explore more practical utilities in the Developer Tools collection.
Related QuickToolFlow Tools
- Timestamp Converter for converting seconds, milliseconds, UTC, and local dates.
- Cron Expression Generator for building recurring schedules.
- JWT Decoder for checking token time claims such as
expandiat.
Keep going